Bom*_*olo 45 xml android android-actionbar
我在网上发现了一些关于这个问题的问题.不幸的是,到目前为止我所尝试的一切都没有成功.
有标题说,我需要更改我的操作栏的背景颜色.
该项目的最小sdk为9,最大sdk为19.
我在我的res/values文件夹中创建了一个xml文件:
red_actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">@color/red</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
colors.xml存储在res/values中
<resources>
<color name="red">#FF0000</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
以及我改变主题的清单部分
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme" >
Run Code Online (Sandbox Code Playgroud)
但没有变化.问题出在哪儿?应用程序接受代码,因为如果我改变了:
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
Run Code Online (Sandbox Code Playgroud)
至
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar ">
Run Code Online (Sandbox Code Playgroud)
它确实改变了我的应用程序的主题,所以问题在于风格,但我不知道如何解决它.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">@color/red</item>
<item name="background">@color/red</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
Bla*_*elt 119
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">@color/red</item>
<item name="background">@color/red</item>
</style>
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)
你需要android:background和background物品.前者适用于本机支持ActionBar的较新版本的android.后者适用于较旧的Android版本.
编辑
而不是<resources>使用
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
Run Code Online (Sandbox Code Playgroud)
来自SDK 21
要更改操作栏背景颜色,将其添加到ActionBarTheme,两种颜色不同或不起作用(感谢@Dre和@lagoman)
<item name="colorPrimary">@color/my_awesome_red</item>
<item name="colorPrimaryDark">@color/my_awesome_darker_red</item>
Run Code Online (Sandbox Code Playgroud)
Zoh*_*han 19
试试这个:
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/red</item>
<item name="background">@color/red</item>
</style>
Run Code Online (Sandbox Code Playgroud)
小智 9
试试这个.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary"> #6699FF </item>
</style>
Run Code Online (Sandbox Code Playgroud)
您可以#6699FF根据您的选择更改颜色(或使用颜色资源).
| 归档时间: |
|
| 查看次数: |
55740 次 |
| 最近记录: |