我们的应用有一些 SwitchPreferences,很难在 Off/On 开关左侧的约 20 个字符内描述。
我看到很多讨论修改偏好特征的问答。例如。 How can I change font size in PreferenceScreen
答案涉及引用要更改的首选项中的布局。
要更改 SwitchPreference 的显示,布局会是什么样子, 这样标题就可以使用屏幕的整个宽度? (文字位于关闭/开启开关上方或下方)
或者是否有其他小部件可以为解释性文本提供更多空间?
最佳答案
(感谢上面 CommonsWare 的评论)
对于大多数首选项
,请在 android:summary
中添加更多详细信息。
例如:
<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" />
对于 SwitchPreference
,通常描述 On
状态就足够了,Off
状态隐式地否定了该状态。在这种情况下,可以使用 android:summary
,就像任何其他 Preference
一样,而不需要 summaryOn
和 summaryOff
。
但是,如果像我的情况一样,对于 SwitchPreference
的每个打开和关闭情况所需的解释略有不同,则必须将附加描述附加到打开和关闭两者摘要:
<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" />
其中文件 values/strings.xml
包含提到的字符串。
关于android - 如何显示长SwitchPreference名称(Android)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30903681/