android - How to set custom layout for PreferenceActivity in Android 3.0?

前端 未结 3 1771
萌比男神i
萌比男神i 2021-02-07 09:15

I am developing app with minSdkVersion=\"11\", that is app for tablets and Android 4.0 and newer. I have scrutinized internet on this topic, but have not found much.

To

相关标签:
3条回答
  • 2021-02-07 09:18

    you do not need to setContenView. in this example case the layout population is done via headers and associated fragments, another words automatically.

    0 讨论(0)
  • 2021-02-07 09:31

    i tried this code for my application

    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
        <PreferenceCategory android:title="@string/PreferencesActivity.GeneralSettingsCategoryTitle">
            <Preference
                android:title="yor title"
                android:summary="your summary"
                android:key="key to access preference" />       
            <Preference
                android:title="@string/"
                android:summary="@string/"
                android:key="key2" />
            <PreferenceScreen
                android:key="key3"
                android:title="@string/"
                android:summary="@string/">
                <CheckBoxPreference
                    android:title="@string/"
                    android:defaultValue="false"
                    android:summary="@string/"
                    android:key="key4" />
                <CheckBoxPreference
                    android:title="@string/"
                    android:defaultValue="true"
                    android:summary="@string/"
                    android:key="key5" />
    
                <ListPreference
                    android:title="@string/"
                    android:summary="@string/"
                    android:key="key6"
                    android:defaultValue="buttons"
                    android:entries="@array/"
                    android:entryValues="@array/" />
                ....
    
    
                    </prefefenceScreen>
          </preferenceCategory>
    </preferenceScreen>
    
    
    
    enter code here
    
    0 讨论(0)
  • 2021-02-07 09:37

    I had the same issue than you.

    I tried a lot of stuff but here is my full code:

    https://github.com/iRail/BeTrains-for-Android/blob/master/src/tof/cv/mpp/MyPreferenceActivity.java

    The trick is to add the setContentView in the onBuildHeaders section, but NOT in the onCreate.

    I also made some tests in fragment and not perfectly sure why this is working, but I promise you: I have a custom layout on tablet header section!

    https://github.com/iRail/BeTrains-for-Android/blob/master/src/tof/cv/mpp/view/StockPreferenceFragment.java

    0 讨论(0)
提交回复
热议问题