Resource Handling

In Mobile SDK template apps, resources reside in XML files in the SalesforceSDK | res project folder. You can customize many of these resources by making changes to these files.

Resources in the /res folder are grouped into categories, including:

  • Drawables—Backgrounds, drop shadows, image resources such as PNG files
  • Layouts—Screen configuration for any visible component, such as the passcode screen
  • Menu—Screens for subviews of the login screen, such as the options menu
  • Values—Strings, colors, and dimensions that are used by Mobile SDK
  • XML—Non-visual configuration settings, such as login server preferences and runtime app restrictions for MDM

Drawable, layout, and value resources are subcategorized into folders that correspond to a variety of form factors. These categories handle different device types and screen resolutions. Each category is defined in its folder name, which allows the resource file name to remain the same for all versions. For example, if the developer provides various sizes of an icon named icon1.png, for example, the smart phone version goes in one folder, the low-end phone version goes in another folder, while the tablet icon goes into a third folder. In each folder, the file name is icon1.png. The folder names use the same root but with different suffixes.

The following table describes the folder names and suffixes.

Folder nameUsage
drawableGeneric versions of drawable resources
drawable-hdpiHigh resolution; for most smart phones
drawable-ldpiLow resolution; for low-end feature phones
drawable-mdpiMedium resolution; for low-end smart phones
drawable-xhdpiResources for extra high-density screens (~320dpi
drawable-xlargeFor tablet screens in landscape orientation
drawable-xlarge-portFor tablet screens in portrait orientation
drawable-xxhdpi-portResources for extra-extra high density screens (~480 dpi)
layoutGeneric versions of layouts
menusAdd Connection dialog and login menu for phones
valuesGeneric styles and values
xmlGeneral app configuration

The compiler looks for a resource in the folder whose name matches the target device configuration. If the requested resource isn’t in the expected folder (for example, if the target device is a tablet, but the compiler can’t find the requested icon in the drawables-xlarge or drawables-xlarge-port folder) the compiler looks for the icon file in the generic drawable folder.

Layouts in the Mobile SDK describe the screen resources that all apps use. For example, layouts configure dialog boxes that handle logins and passcodes.

The name of an XML node in a layout indicates the type of control it describes. For example, the following TextView node from res/layout/sf__passcode.xml describes a text edit control:

In this case, the TextView control is read-only. The style attribute references a global style defined elsewhere in the resources. Instead of specifying style attributes in place, you define styles defined in a central file, and then reference the attribute anywhere it’s needed. The value @style/SalesforceSDK.Passcode.Text.Title refers to an SDK-owned style defined in res/values/sf__styles.xml. Here’s the style definition.

You can override any style attribute with a reference to one of your own styles. Rather than changing sf__styles.xml, define your styles in a different file, such as xyzcorp__styles.xml. Place your file in the res/values for generic device styles, or the res/values-xlarge folder for tablet devices.

The res/values and res/values-xlarge folders contain definitions of style components, such as dimens and colors, string resources, and custom styles. File names in this folder indicate the type of resource or style component.

File nameContains
sf__attr.xmlColor and integer values used by the Passcode screen
sf__colors.xmlColors referenced by Mobile SDK styles
sf__dimens.xmlDimensions referenced by Mobile SDK styles
sf__strings.xmlStrings referenced by Mobile SDK styles; error messages can be overridden
sf__styles.xmlVisual styles used by the Mobile SDK
strings.xmlApp-defined strings

You can override the values in strings.xml. To provide your own values, create new files in the same folders using a file name prefix that reflects your own company or project. For example, if your developer prefix is XYZ, you can override sf__styles.xml in a new file named XYZ__styles.xml.

Two other folders contain Mobile SDK resources.

  • res/menu defines menus used internally. If your app defines new menus, add them as resources here in new files.

  • res/xml includes one file that you must edit: servers.xml. In this file, change the default Production and Sandbox servers to the login servers for your org. The other files in this folder are for internal use. The authenticator.xml file configures the account authentication resource, and the config.xml file defines PhoneGap plug-ins for hybrid apps.