我在如何创建自定义 PreferenceCategory 的教程中看到了很多关于这个问题的答案和线程。没有什么对我有用。我的主题只是没有应用。
PreferenceActivity 类:
public class PreferencesActivity extends PreferenceActivity{
private MyPreferenceFragment preferences;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences = new MyPreferenceFragment();
getFragmentManager().beginTransaction().replace(android.R.id.content, preferences).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment
{
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.mypreferences);
}
}
}
安卓清单:
<activity android:name="com.gpsy.preferences.PreferencesActivity"
android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation"
android:theme="@style/Custom">
</activity>
样式.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="PreferenceListHeader" >
<item name="android:textColor">#000000</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">12sp</item>
<item name="android:background">@color/Gray</item>
<item name="android:paddingTop">6dp</item>
<item name="android:paddingBottom">6dp</item>
<item name="android:paddingLeft">12dp</item>
</style>
<style name="Custom" parent="@android:Theme.Light.NoTitleBar">
<item name="android:listSeparatorTextViewStyle">@style/PreferenceListHeader</item>
</style>
</resources>
mypreferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<PreferenceCategory
android:title="@string/gps_settings">
<ListPreference
android:key="nav_systems_preference"
android:title="@string/my_nav_app"
android:summary="summary_checkbox_preference"/>
</PreferenceCategory>
</PreferenceScreen>
另外,我尝试通过以下方式应用主题但没有成功:
setTheme(R.style.Custom);
尝试将 PreferenceCategory 标记更改为
<PreferenceCategory android:widgetLayout="@style/Custom"
android:title="@string/gps_settings">