6

의 요약 필드 :나는 이런 식으로 뭔가를 보았다 PreferenceCategory 태그

<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> 

하지만 왜 현 범주에 대한 요약 필드가 그것을 얻을하지 않습니다

(android:summary="Preferences related to vegetable"가)?

프리뷰 화면을 사용하면 요약이보기에 표시되지만 프리프 카테고리에서는 그렇지 않습니다. 선행 카테고리에 요약의 존재 여부는 어떻게 든 볼 수 있습니다.

pref category 요소에서 summary의 실제 사용법은 무엇입니까?

답변

9

표준 PreferenceCategory 위젯은 제목 만 표시합니다. android:summary 속성은 무시됩니다. 당신은뿐만 아니라 요약을 표시하려는 경우, 당신은 android:layout 속성을 사용하여 자신의 레이아웃을 지정할 수 있습니다

<!-- 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" 
/> 

: 기본 레이아웃 (preference_category.xml)는 제목 필드에 대한 단 하나의 텍스트 뷰가 포함되어 있기 때문에입니다

. 예를 들면 :

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

레이아웃/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> 

당신이 가서이 작업을 수행하기 전에, 그러나, 당신이 사용자에게 덜 이상의 혼란 여부를 고려해야한다. 주의 깊게 요약 텍스트의 스타일을 지정하지 않으면 화면 밖으로 튀어 나오거나 해당 범주의 첫 번째 기본 설정에 연결되는 것처럼 보입니다.

7

기본 설정 및 Android : 요약을 사용할 수 있습니다.

<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> 
+0

이 작품 특별한 화면 크기에 대한 diff를한다. 하지만 아주 좋은 성능이 아닙니다. –

+0

나는 이것이 잘 작동한다는 것을 안다. (레이아웃을 바꾸는 것에 비해 안드로이드 버전과 룩앤필이 일치해야하기 때문에). 추가적으로'android : selectable = false'를 추가하면 비슷한 모양과 느낌을 얻을 수 있습니다. –

0

@ehartwell는 DIFF 버전
내 레이아웃이 절대적으로 옳다 :
에 대한
에 대한

<?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> 

포스트 - 롤리팝 사전 롤리팝

<?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:paddingLeft="@dimen/preference_category_margin" 
    android:paddingRight="@dimen/preference_category_margin" 
    android:orientation="vertical"> 

    <TextView android:id="@android:id/title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="6dp" 
    android:textStyle="bold" 
    android:textSize="13sp" 
    android:textAllCaps="false" 
    android:textColor="@color/colorAccent"/> 

    <TextView android:id="@android:id/summary" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textSize="12sp" 
    android:textColor="@color/colorAccent" 
    android:textAllCaps="false"/> 

</LinearLayout> 

DIMEN @/preference_category_margin는
16dp 또는 24dp
그들은 꽤 잘됩니다 :)

관련 문제