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

ぃ、小莉子 提交于 2019-12-03 05:11:45

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!