【问题标题】:Android: Changing the colour of the action barAndroid:更改操作栏的颜色
【发布时间】:2015-03-17 07:01:01
【问题描述】:

我之前将窗口背景的颜色设置为白色,现在我尝试将操作栏的颜色更改为绿色。这是我的 xml 代码:

<style name = "CustomAppTheme2" parent = "android:Widget.Holo.Light">

    <item name="android:windowBackground">@color/white</item>
    <item name="android:background">@color/green</item>
    <item name="android:icon">@android:color/transparent</item> 
</style>

问题是使用android:background改变action bar的颜色,溢出,把整个屏幕的颜色变成绿色。我想要一个清晰的绿色操作栏和它下面的白色窗口。提前致谢!

【问题讨论】:

标签: android xml colors android-actionbar customization


【解决方案1】:
     <!-- Base application theme. -->
        <style name="AppTheme" parent="@style/CustomActionBarTheme">
            <!-- Customize your theme here. -->
        </style>
        <!-- the theme applied to the application or activity -->
        <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

            <!-- Support library compatibility -->

            <item name="android:actionBarStyle">@style/MyActionBar</item>

            <!-- Support library compatibility -->
            <item name="actionBarStyle">@style/MyActionBar</item>
        </style>

        <!-- ActionBar styles -->
        <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
            <item name="android:background">@drawable/top_bar_blue</item>

            <!-- Support library compatibility -->
            <item name="background">@drawable/top_bar_blue</item>
            <item name="titleTextStyle">@style/myTheme.ActionBar.Text</item>
        </style>
    <!-- ActionBar Text -->
        <style name="myTheme.ActionBar.Text" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
            <item name="android:textColor">@android:color/white</item>
            <item name="android:textSize">20sp</item>
            <item name="android:textStyle">bold</item>
            <item name="android:fontFamily">sans-serif-bold</item>
        </style>
<!-- In Manifest -->
android:theme="@style/AppTheme"

【讨论】:

  • 非常感谢。 UP我的问题,这样我就可以UP你的答案:)
【解决方案2】:

您可以从您的一个类扩展 ActionBarActivity 并执行以下操作:

ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(mTitle);

//Change the color of the actionbar by changing the value in the next line
actionBar.setBackgroundDrawable(new ColorDrawable(#FFFFFF));

【讨论】:

  • 感谢您的帮助!请UP我的问题,以便我可以UP你的答案:)
猜你喜欢
  • 1970-01-01
  • 2014-12-16
  • 1970-01-01
  • 1970-01-01
  • 2015-02-25
  • 1970-01-01
  • 2015-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多