我见过这样的事情:
<PreferenceCategory xmlns:android="http://schemas.android.com/apk/res/android"
android:key="vegi_category" android:title="Vegetables"
android:summary="Preferences related to vegetable"> <!-- Why is this here? -->
<CheckBoxPreference android:key="tomato_selection_pref"
android:title="Tomato " android:summary="It's actually a fruit" />
<CheckBoxPreference android:key="potato_selection_pref"
android:title="Potato" android:summary="My favorite vegetable" />
</PreferenceCategory>
但是我不明白为什么有pref类别的摘要字段:
(android:summary="Preferences related to vegetable"
)?
当我使用pref屏幕时,摘要会显示在视图中,但这不是pref类别的情况。是否可以以某种方式看到pref类别中的摘要的存在只是一种约定?
pref类别元素中摘要的实际用法是什么?
答案 0 :(得分:10)
标准的PreferenceCategory小部件仅显示标题; <{1}}属性被忽略。
那是因为默认布局(preference_category.xml)只包含标题字段的单个TextView:
android:summary
如果您还想显示摘要,可以使用<!-- Layout used for PreferenceCategory in a PreferenceActivity. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/listSeparatorTextViewStyle"
android:id="@+android:id/title"
/>
属性指定自己的布局。例如:
android:layout
layout / preference_category_summary.xml的位置如下:
<PreferenceCategory android:title="Category" android:summary="This is the summary"
android:layout="@layout/preference_category_summary">
然而,在你继续这样做之前,你应该考虑它对用户来说是否更少或更混乱。除非您仔细设置摘要文本的样式,否则它将跳出屏幕或显示为附加到类别中的第一个首选项。
答案 1 :(得分:7)
你可以使用Preference和android:summary。
<PreferenceCategory xmlns:android="http://schemas.android.com/apk/res/android"
android:key="vegi_category" android:title="Vegetables">
<Preference android:summary="Preferences related to vegetable" />
<CheckBoxPreference android:key="tomato_selection_pref"
android:title="Tomato " android:summary="It's actually a fruit" />
<CheckBoxPreference android:key="potato_selection_pref"
android:title="Potato" android:summary="My favorite vegetable" />
</PreferenceCategory>
答案 2 :(得分:0)
alert
棒棒糖后
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:textSize="14sp"
android:textStyle="bold"
android:textAllCaps="true"
android:paddingLeft="8dp"
android:paddingRight="8dp"/>
<TextView android:id="@android:id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:textSize="12sp"
style="?android:attr/listSeparatorTextViewStyle"/>
</LinearLayout>
@ dimen / preference_category_margin是特殊屏幕尺寸的差异
16dp或24dp
它们非常好:))