【发布时间】:2017-08-03 05:45:23
【问题描述】:
我遇到了一个问题,即更改支持 ActionBar 的背景可绘制对象会更改大部分栏的颜色,但会在文本和图标周围留下旧颜色。我尝试更改支持 ActionBar 和我用来制作它的 ToolBar 的颜色。我尝试了许多使 UI 元素无效的不同方法。我已经厌倦了设置颜色和文本是不同的顺序。我试过隐藏和显示文本。我就是不能让它变成一种纯色。
以下是我的 ActionBar 样式:
<style name="LocationBar" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/text_color_primary_inverse</item>
<item name="android:textColorSecondary">@color/text_color_primary_inverse</item>
<item name="android:background">@color/weather_cool</item>
</style>
这就是我将它添加到我的活动中的方式:
<android.support.v7.widget.Toolbar
android:id="@+id/location_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/LocationBar"/>
这个在Java代码中我设置为supportActionBar:
_locationBar = (Toolbar)findViewById(R.id.location_bar);
setSupportActionBar(_locationBar);
然后在获取天气后,我尝试像这样调整颜色:
ColorDrawable warmDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.weather_warm));
getSupportActionBar().setBackgroundDrawable(warmDrawable);
这会导致您在图片中看到的内容。大部分栏会改变颜色,但不是全部。
【问题讨论】:
-
你能分享你的
styles.xml吗? -
改变主题可以在这里工作。
-
我添加了更多信息。抱歉,来晚了,我没想到!
标签: android android-actionbar android-actionbar-compat