2016-02-04 9 views
5

लॉलीपॉप पर एंड्रॉइड सिस्टम वरीयता स्क्रीन "कार्ड लेआउट" जैसा दिखने वाला एक लेआउट का उपयोग कर प्रतीत होता है।Android सिस्टम वरीयताओं को कैसे प्राप्त करें?

enter image description here

मैं अपने ऐप के लिए एक ही झलक पाने के लिए कोशिश कर रहा हूँ, लेकिन नहीं देख सकते हैं कि वे किस तरह यह डिफ़ॉल्ट PreferenceFragment के साथ हासिल की। क्या कोई मुझे समझा सकता है, मैं अपनी प्राथमिकताओं को लिखने के बिना एक ही प्रभाव कैसे प्राप्त कर सकता हूं?


ध्यान दें कि मैंने देखा और इन सवालों को पढ़ लिया है, लेकिन वे एक उपयुक्त जवाब प्रदान नहीं करते हैं:।

  • How to achieve preference category cards like Android System Settings (उत्तर बस एक ऐसा प्रतिरूप समान दिखता है बनाने के लिए कैसे पता चलता है कुछ भी नहीं करने के लिए PreferenceFragment के साथ क्या)
  • Android Lollipop Sections Separator/Divider (वरीयताओं स्क्रीनशॉट को संदर्भित करता है, लेकिन ओ पी PreferenceFragment करने के लिए इसे लागू करने के लिए)
चाहते प्रतीत नहीं होता है 10

यह ब्याज की है, तो मेरे वर्तमान प्राथमिकताएं एक्सएमएल इस तरह दिखता है:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:custom="http://schemas.android.com/apk/res-auto"> 

    <PreferenceCategory android:title="@string/preferences_title_general"> 
     <Preference 
      android:key="Prefs.Delete.Row.Token" 
      android:summary="@string/preferences_delete_row_token_summary" 
      android:title="@string/preferences_delete_row_token_title"/> 
     <Preference 
      android:key="Prefs.Delete.Cell.Token" 
      android:summary="@string/preferences_delete_cell_token_summary" 
      android:title="@string/preferences_delete_cell_token_title"/> 
     <Preference 
      android:key="Prefs.Null.Token" 
      android:summary="@string/preferences_null_token_summary" 
      android:title="@string/preferences_null_token_title"/> 
    </PreferenceCategory> 
    <PreferenceCategory android:title="@string/preferences_title_appearance"> 
     <SwitchPreference 
      android:dialogTitle="@string/preferences_theme_title" 
      android:key="Prefs.Appearance.Theme" 
      android:summaryOff="@string/preferences_theme_summary_off" 
      android:summaryOn="@string/preferences_theme_summary_on" 
      android:switchTextOff="@string/general_no" 
      android:switchTextOn="@string/general_yes" 
      android:title="@string/preferences_theme_title"/> 
    </PreferenceCategory> 
    <PreferenceCategory android:title="@string/preferences_title_misc"> 
     <SwitchPreference 
      android:dialogTitle="@string/preferences_read_back_title" 
      android:key="Prefs.Voice.Feedback" 
      android:switchTextOff="@string/general_no" 
      android:switchTextOn="@string/general_yes" 
      android:title="@string/preferences_read_back_title"/> 
     <Preference 
      android:key="Prefs.Export.Barcode.Properties" 
      android:title="@string/preferences_export_title" 
      android:summary="@string/preferences_export_summary"/> 
     <Preference 
      android:key="Prefs.Show.Eula" 
      android:title="@string/preferences_eula_title" 
      android:summary="@string/preferences_eula_summary"/> 
    </PreferenceCategory> 

</PreferenceScreen> 

और मैं PreferenceFragment का विस्तार करने और के माध्यम से

addPreferencesFromResource(R.xml.prefs); 
+0

, किसी भी एपीआई> 20 हाथ में डिवाइस है, आप को देखने का प्रयास किया था मत करो यह आपके डिवाइस मॉनीटर के साथ -> दृश्य पदानुक्रम डंप करें? –

+0

@ डेविड मैडेनजाक ऐसा करना जो मुझे लेआउट का पदानुक्रम देता है। अब मैं इसके साथ क्या करूँ? जैसा कि मैंने कहा, मैं लेआउट संरचना को सामान्य लेआउट में पुन: उत्पन्न नहीं कर रहा हूं, लेकिन मैं अपने मौजूदा 'वरीयता फ्रेगमेंट' को वही दिखाना चाहता हूं। – Baz

उत्तर

4

एक्सएमएल लोड मैं जोड़कर इस "हल" है

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:custom="http://schemas.android.com/apk/res-auto"> 
    <PreferenceCategory></PreferenceCategory> 

    <Preference layout="@layout/preference_divider" /> 

    <PreferenceCategory></PreferenceCategory> 
</PreferenceScreen> 
: एक डमी Preference PreferenceCategory आइटम के बीच एक लेआउट जो सवाल में स्क्रीनशॉट में नज़र mimmicks का उपयोग करता है

एक ऐसा प्रतिरूप कुछ इस तरह दिखता है:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:custom="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 

    <View  android:layout_width="match_parent" 
       android:layout_height="5dp" 
       android:background="@drawable/shadow_bottom" /> 

    <View  android:layout_width="match_parent" 
       android:layout_height="5dp" 
       android:background="@drawable/shadow_top" /> 

</LinearLayout> 
+0

आपने shadow_top और shadow_bottom को कैसे परिभाषित किया है? –

+0

@ जेवियर डेलगाडो वे सिर्फ छवियां हैं ([9-पैच] (https://developer.android.com/studio/write/draw9patch.html))। – Baz

+0

क्या आप उन्हें साझा करने का कोई मौका देते हैं? – JayTee

0

मेरे लिए यह एक कस्टम लेआउट के माध्यम से एक पृष्ठभूमि सेट करने के लिए काम नहीं किया। इसके अलावा ऊंचाई लागू नहीं हुई थी।

वह मेरे लिए हालांकि काम किया:

public class PreferenceDivider extends Preference { 
    public PreferenceDivider(Context context) { 
     super(context); 
    } 
    public PreferenceDivider(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 
    @Override 
    protected View onCreateView(ViewGroup parent) { 
     Resources res=getContext().getResources(); 
     View v=super.onCreateView(parent); 
     v.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, res.getDimensionPixelSize(R.dimen.divider_height))); 
     v.setBackground(res.getDrawable(R.drawable.preference_category_divider, null)); 
     return v; 
    } 
} 

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:custom="http://schemas.android.com/apk/res-auto"> 
    <PreferenceCategory/>> 

    <your.package.path.PreferenceDivider/> 

    <PreferenceCategory/>> 

</PreferenceScreen> 

9 पैच छवियों यहां हैं: https://drive.google.com/file/d/1M5uXXnFc0HHx2BOHQqLtvAXFet4ICDj0/view?usp=sharing

संबंधित मुद्दे