我有一个偏好片段:
import android.os.Bundle;
import android.preference.PreferenceFragment;
public class SettingsFragment extends PreferenceFragment{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
加载此xml资源文件:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceCategory
android:title="Checkbox Preference">
<CheckBoxPreference
android:key="update"
android:defaultValue="True"
android:summary="joo"
android:textColor="@color/colorText"
android:textSize="40dp"
android:title="@string/prefUpdate"/>
<CheckBoxPreference
android:key="inspection"
android:defaultValue="False"
android:summary="joo"
android:textColor="@color/colorText"
android:textSize="40dp"
android:title="@string/prefInspection"/>
</PreferenceCategory>
我在此活动中显示它:
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentManager settingsFM = getFragmentManager();
FragmentTransaction settingsFT = settingsFM.beginTransaction();
settingsFT.replace(android.R.id.content, new SettingsFragment());
settingsFT.commit();
}
}
此活动的主题是:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorWindowBackground</item>
<item name="android:windowActionBar">false</item>
</style>
问题是,没有显示android:summary和android:title,只有复选框可见。文本颜色设置为黑色,背景颜色设置为白色。
编辑:不知何故,文字颜色设置为黑色,但标题和摘要为白色
我的颜色:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FFFFFF</color>
<color name="colorWindowBackground">#FFFFFF</color>
<color name="colorText">#000000</color>
<color name="colorButtonPressed">#2a3993</color>
<color name="colorGrayDivision">#484848</color>
</resources>