如何更改android中actionbar的颜色 [英] how to change the color of actionbar in android

查看:203
本文介绍了如何更改android中actionbar的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将ActionBar的颜色更改为蓝色。为了实现这一点,我将styles.xml更改为

i want to change the color of ActionBar into blue. In order to acheive this i changed the styles.xml as

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->.
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">#0000FF</item>
    </style>





并将manifest.xml中的android:theme更改为MyActionBar
运行应用程序
我收到错误:

java.lang.IllegalStateException:你需要在这个活动中使用一个Theme.AppCompat主题(或后代)。



我犯了哪个错误。请需要指导



and changed the android:theme in manifest.xml to MyActionBar
on running the app i get an error :
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

where have i made the mistake. please need guidence

推荐答案

看看这个: http://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-与此活动 [ ^ ]


<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

        <item name="colorPrimary">@color/yourColorResource</item>
        <!-- Customize your theme here. -->
    </style>

</resources>





而不是@ color / yourColorResource,你可以直接使用颜色的十六进制代码或Android的预定义资源。



Instead of @color/yourColorResource, you can directly use a color's hexcode or Android's pre-defined resources.


这篇关于如何更改android中actionbar的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆