我想在操作栏中更改颜色并更改后面的窄图标。它的工作当我只是改变后面的狭窄,但当我在动作栏中设置颜色样式时,图标就消失了。我想将动作栏的颜色更改为蓝色。
这是我在xml中的代码:
<?xml version="1.0" encoding="utf-8"?>
<!--
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="android:Theme.Holo.Light.DarkActionBar">
<!--
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>
<style name="AppBaseAlternativeTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="AppAlternativeTheme" parent="AppBaseAlternativeTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="CustomUpIndicatorTheme" parent="AppAlternativeTheme">
<item name="android:homeAsUpIndicator">@drawable/ic_up_indicator</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">@color/action_bar</item>
</style>
答案 0 :(得分:5)
您可以使用以下活动中的代码执行此操作。
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_actionbar_screen_back);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_background_color)));
答案 1 :(得分:2)
试一试 -
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#ffffffff"));
getSupportActionBar().setBackgroundDrawable(colorDrawable);