
问题
当我设置Actionbar背景颜色时,条形如下所示:
我不能在这里上传图像,所以这里是文件:
Android ActionBar Problem
我的值/样式文件
<?xml version="1.0" enCoding="utf-8"?><resources xmlns:androID="http://schemas.androID.com/apk/res/androID"><!-- Base application theme, dependent on API level. This theme is replaced by AppBasetheme from res/values-vXX/styles.xml on newer devices.--><style name="AppBasetheme" parent="theme.AppCompat.light"> <!-- theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --></style><!-- Application theme. --><style name="Apptheme" parent="AppBasetheme"> <item name="actionbarStyle">@style/Actionbartheme</item></style><!-- Action bar theme --><style name="Actionbartheme" parent="@style/theme.AppCompat.light.DarkActionbar"> <item name="androID:background">@drawable/actionbar</item> <item name="background">@drawable/actionbar</item></style><style name="Fullscreentheme" parent="androID:style/theme.NoTitlebar.Fullscreen"> <item name="androID:windowContentOverlay">@null</item> <item name="androID:windowBackground">@null</item> <item name="MetabuttonbarStyle">@style/buttonbar</item> <item name="MetabuttonbarbuttonStyle">@style/buttonbarbutton</item></style><style name="buttonbar"> <item name="androID:paddingleft">2dp</item> <item name="androID:paddingtop">5dp</item> <item name="androID:paddingRight">2dp</item> <item name="androID:paddingBottom">0dp</item> <item name="androID:background">@androID:drawable/bottom_bar</item></style><style name="buttonbarbutton" /></resources>我的清单文件
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"package="com.application"androID:versionCode="1"androID:versionname="1.0" ><uses-sdk androID:minSdkVersion="11" androID:targetSdkVersion="19" /><application androID:allowBackup="true" androID:icon="@drawable/symbol" androID:label="@string/app_name" androID:theme="@style/Apptheme" > <activity androID:name="com.application.Main" androID:configChanges="orIEntation|keyboardHIDden|screenSize" androID:label="@string/app_name" androID:screenorIEntation="portrait" androID:theme="@style/Fullscreentheme" > <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity androID:name="com.application.Settings" androID:parentActivityname="com.application.Main" androID:screenorIEntation="portrait" androID:theme="@style/Actionbartheme"> <Meta-data androID:name="androID.support.PARENT_ACTIVITY" androID:value="com.application.Main" /> </activity> <activity androID:name="com.application.DateList" androID:configChanges="orIEntation|keyboardHIDden|screenSize" androID:screenorIEntation="portrait" androID:theme="@style/Fullscreentheme" > </activity></application></manifest>我也试过这个,但同样的事情发生了
colorDrawable draw = new colorDrawable(R.color.grey);getSupportActionbar().setBackgroundDrawable(draw);我的颜色抽屉
<shape xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:shape="rectangle"> <solID androID:color="@color/grey" /></shape>解决方法:
getSupportActionbar().setBackgroundDrawable(draw);应该是,在你的情况下
getSupportActionbar().setBackgroundDrawable(getResources.getDrawable(R.drawable.your_drawable_name);colorDrawable的构造函数采用表示颜色的int,而不是颜色的ID.使用instenad
colorDrawable draw = new colorDrawable(getResources().getcolor(R.color.grey));
编辑:
关于style.xml,你需要带有和没有androID前缀的项目:
<!-- Application theme. --><style name="Apptheme" parent="AppBasetheme"> <item name="androID:actionbarStyle">@style/Actionbartheme</item> <item name="actionbarStyle">@style/Actionbartheme</item></style>由于minSDK值,lint可能会抱怨它.如果是,你可以添加工具:ignore =“NewAPI”到具有androID:前缀的项目.例如:
<item name="androID:actionbarStyle" tools:ignore="NewAPI">@style/Actionbartheme</item> 总结 以上是内存溢出为你收集整理的无法正确设置Android *** 作栏背景全部内容,希望文章能够帮你解决无法正确设置Android *** 作栏背景所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)