我遇到了更改支持ActionBar的背景可繪製更改大多數欄的顏色但在文本和圖標周圍留下舊顏色的問題。我試着改變了我用來製作它的支持ActionBar和ToolBar的顏色。我已經嘗試了許多不同的UI元素失效方式。我累了設置顏色和文字是不同的命令。我試圖隱藏和顯示文字。我不能讓它變成一種純色。以編程方式更改supportActionBar的顏色
這裏就是我有我的動作條的風格:
<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'? – azizbekian
更改主題可以在這裏工作。 –
我添加了很多更多的信息。對不起,這是遲到了,我沒有想到! – CaseyB