6

私はこのようなものを見てきました:

<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 カテゴリ要素での概要の実際の使用法は何ですか?

4

3 に答える 3

11

標準のPreferenceCategoryウィジェットには、タイトルのみが表示されます。属性はandroid:summary無視されます。

これは、デフォルトのレイアウト(preference_category.xml)にタイトルフィールドのTextViewが1つだけ含まれているためです。

<!-- 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属性を使用して独自のレイアウトを指定できます。例えば:

<PreferenceCategory android:title="Category" android:summary="This is the summary"
                    android:layout="@layout/preference_category_summary">

layout/preference_category_summary.xmlは次のようなものです。

<!-- Layout used for PreferenceCategory + SUMMARY in a PreferenceActivity. -->
<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" 
              style="?android:attr/listSeparatorTextViewStyle"/>
    <TextView android:id="@+android:id/summary"
              android:paddingLeft="5dip" android:paddingRight="dip"
              android:layout_width="match_parent" android:layout_height="wrap_content"/>
</LinearLayout>

ただし、先に進んでこれを行う前に、ユーザーの混乱が少ないか多いかを検討する必要があります。要約テキストのスタイルを慎重に設定しない限り、画面から飛び出すか、カテゴリの最初の設定に添付されているように見えます。

于 2012-04-11T02:27:08.090 に答える
8

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>
于 2013-10-03T18:03:10.743 に答える