[英]Actionbar wont change color for Theme.AppCompat.Light
AndroidManifest.xml中
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat" >
<activity
android:name=".MainActivity"
android:label="@string/cb_campaign"
android:logo="@mipmap/ic_launcher"
android:theme="@style/MyTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
styles.xml
<resources>
<style name="MyTheme" parent="@android:style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#FFCA09</item>
</style>
</resources>
MainActivity.java
public class MainActivity extends AppCompatActivity{
}
编辑:原始问题是:如何解决Android错误:java.lang.IllegalStateException:您需要使用Theme.AppCompat
更改了AndroidManifest.xml
<style name="MyTheme" parent="@style/Theme.AppCompat.Light">
但是动作背景颜色仍然不会改变。
只需打开“设计”视图,然后单击“ AppTheme”按钮,然后更改主题即可。
就这样。
你可以从这里学到一些材料设计cheesesquare
您需要省略“ android:”以使用向后兼容的属性:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<!--Backwards compatibility-->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/red</item>
<!--Backwards compatibility-->
<item name="background">@color/red</item>
</style>
<color name="red">#FF0000</color>
</resources>
对样式资源的引用,该样式资源为应用程序中的所有活动定义了默认主题。 各个活动可以通过设置自己的主题属性来覆盖默认设置。 有关更多信息,请参见样式和主题开发人员指南。
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat">
<activity
android:name=".MainActivity"
android:label="@string/cb_campaign"
android:logo="@mipmap/ic_launcher"
android:theme="@style/MyTheme">
<application>
标记中的android:theme =“ @ style / Theme.AppCompat”您需要应用您的主题。 一个建议最好与材料设计stackoverflow链接一起使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.