How display long SwitchPreference name (Android)?

1k views Asked by At

Our app has some SwitchPreferences which are difficult to describe within the ~ 20 characters to the left of the Off/On switch.

I see lots of Q&A's that discuss modifying characteristics of preferences. E.g. How can I change font size in PreferenceScreen

The answers involve referencing a layout from the preference(s) to be altered.

What would a layout look like, to change the display of a SwitchPreference, so that the title could use the full width of the screen? (With the text above or below the Off/On Switch)

Or is there a different widget that would have more room for explanatory text?

1

There are 1 answers

0
ToolmakerSteve On

(Thanks to CommonsWare's comment above)

For most Preferences, put additional detail in android:summary.

Ex:

    <SwitchPreference
        android:defaultValue="true"
        android:key="your_pref_key"
        android:title="@string/your_short_pref_title"
        android:summary"=@string/long_description_that_gives_more_explanation" />

For a SwitchPreference, usually it is sufficient to describe the On state, with the Off state implicitly being the negation of that. In this case, can use android:summary, like any other Preference rather than needing summaryOn and summaryOff.

HOWEVER, If, as in my case, there is slightly different explanation desired for each of the On and Off cases of a SwitchPreference, then the additional description must be appended to both the On and Off summaries:

    <SwitchPreference
        android:defaultValue="true"
        android:key="your_pref_key"
        android:title="@string/your_short_pref_title"
        android:summaryOn"=@string/summary_on_with_extra_description"
        android:summaryOff"=@string/summary_off_with_extra_description" />

where file values/strings.xml contains the mentioned strings.