【问题标题】:PreferenceActivity action bar background colorPreferenceActivity 操作栏背景颜色
【发布时间】:2014-01-27 13:44:50
【问题描述】:

亲爱的, 看快照:

我使用以下代码更改操作栏背景-与正常活动中使用的相同并且工作正常-:

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.actionbar_background));
    actionBar.setIcon(R.drawable.ic_settings);

    setupSimplePreferencesScreen();
}

问题是action bar背景颜色变成了指定颜色,但是text和icon背景取了activity背景颜色。

怎么了?

【问题讨论】:

    标签: android android-actionbar


    【解决方案1】:

    此链接帮助我解决问题:

    My action bar title is taking the wrong color from theme

    问题在于设置 Activity 背景颜色,而不是这样:

    <!-- Settings Activity -->
    
      <style name="SettingsTheme">
        <item name="android:Background">@color/main_menu_background</item>
        <item name="android:textColor">@color/font_color</item>
      </style>
    

    我用这个:

    <!-- Settings Activity -->
    
      <style name="SettingsTheme">
        <item name="android:windowBackground">@color/main_menu_background</item>
        <item name="android:textColor">@color/font_color</item>
      </style>
    

    【讨论】:

      【解决方案2】:

      变化:

      actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.actionbar_background));
      

      收件人:

      actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_background)));
      

      【讨论】:

      • 嗨,它给了我这个错误The method setBackgroundColor(int) is undefined for the type ActionBar。建议改成setBackgroundDrawable。还有其他建议吗?
      猜你喜欢
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-18
      • 1970-01-01
      相关资源
      最近更新 更多