本人刚接触preference,现在有一问题。就是在创建<preference_headers>xml布局文件时,发现并没有这个可选的布局文件。如下图
在网上说是以3.0为分界线,3.0系统以上才会支持<preference_headers> 但是我把编译环境调成3.0以上了,而且目标AVD还是4.0的。但还是没有该xml文件能进行创建。。如图
疑问:
1,为什么我是android3.0了还不能创建?
2,我的不是android3.0么?
3,虽然<preference_headers>功能和<preferenceScreen>内嵌的<preference>老版本类似,但不清楚他们的区别,结构上也好。
如果你的应用程序既支持3.0以下的版本,也支持3.0以上的版本,要么3.0以上我们使用headers能提供双面板布局。低于3.0的版本我们就可以添加额外的preferences XML但里面不是使用<header>而是使用<Preference>节点了。但每一个<Preference>都发送一个intent到PreferenceActivity。例如让我们先看下3.0或以上版本的代码清单5-13中(res/xml/preference_headers.xml):
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
    <header 
        android:fragment="com.example.prefs.SettingsFragmentOne"
        android:title="@string/prefs_category_one"
        android:summary="@string/prefs_summ_category_one" />
    <header 
        android:fragment="com.example.prefs.SettingsFragmentTwo"
        android:title="@string/prefs_category_two"
        android:summary="@string/prefs_summ_category_two" />
</preference-headers>
然后让我们再看下3.0以下版本的代码清单5-14中(res/xml/preference_headers_legacy.xml):
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <Preference 
        android:title="@string/prefs_category_one"
        android:summary="@string/prefs_summ_category_one"  >
        <intent 
            android:targetPackage="com.example.prefs"
            android:targetClass="com.example.prefs.SettingsActivity"
            android:action="com.example.prefs.PREFS_ONE" />
    </Preference>
    <Preference 
        android:title="@string/prefs_category_two"
        android:summary="@string/prefs_summ_category_two" >
        <intent 
            android:targetPackage="com.example.prefs"
            android:targetClass="com.example.prefs.SettingsActivity"
            android:action="com.example.prefs.PREFS_TWO" />
    </Preference>
</PreferenceScreen>希望有经验的人都来谈谈android PreferenceScreenpreference-headers应用程序3.0