首选项活动中的偏好片段会忽略文本颜色

时间:2018-09-28 17:34:33

标签: android android-layout

我的首选项活动有问题,其片段忽略了主题的“ primaryTextColor”和“ secondaryTextColor”(背景已正确应用)。当我使用深色主题results

时,会得到此结果

我尝试播放主题,但一直被忽略

public class SettingsPrefActivity extends AppCompatActivity {
   @BindView(R.id.toolbar)
   android.support.v7.widget.Toolbar toolbar;
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.NoActionBarDarkTheme);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        ButterKnife.bind(this);
        LayoutHelper.setupToolbar(this,toolbar,R.drawable.ic_baseline_arrow_back);
        getSupportActionBar().setTitle(R.string.settings);
        // load settings fragment
        getFragmentManager().beginTransaction().replace(R.id.content_frame, new MainPreferenceFragment()).commit();
        }
public static class MainPreferenceFragment extends PreferenceFragment {
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.pref_main);
        Preference theme = findPreference(getString(R.string.key_theme));
        theme.setOnPreferenceChangeListener((preference, o) -> {
            //do something
        });
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onBackPressed();
    }
    return super.onOptionsItemSelected(item);
}


}

我尝试在调用onCreate之后放置setTheme,但是它不起作用。 我应该以另一种方式为我的片段设置主题吗?

编辑:这是我的appTheme

<style name="AppThemeDark" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/redSapienza</item>
    <item name="colorPrimaryDark">@color/redSapienzaDark</item>
    <item name="colorAccent">@android:color/holo_red_light</item>
    <item name="colorSecondary">#c91515</item>
    <item name="colorButtonNav">#e14242</item>
    <item name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
    <item name="primaryTextColor">#F4F4F6</item>
    <item name="secondaryTextColor">#96F4F4F6</item>
    <item name="backgroundCardColor">#424242</item>
    <item name="dividerColor">#96F4F4F6</item>
    <item name="backgroundColor">#212121</item>
    <item name="android:navigationBarColor">#212121</item>
    <item name="defaultTextNav">@android:color/white</item>
    <item name="colorNavText">@android:color/white</item>
    <item name="bottomNavColor">#303030</item>
    <item name="certifiedExamColor">@color/greenLight</item>
    <item name="nonPassedExamColor">@color/redLight</item>
    <item name="nonCertifiedExamColor">@color/yellowLight</item>
    <item name="colorHeader">@color/redSapienzaDark</item>
</style>

<style name="NoActionBarAppDarkTheme" parent="AppThemeDark">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

0 个答案:

没有答案