Tôi đang cố gắng để thay đổi màu sắc thanh công cụ Background lập trình bằng cách làm này:Thay đổi Toolbar lập trình không thay đổi Toolbar Tiêu đề Màu nền
getSupportActionBar().setBackgroundDrawable(newColorDrawable(getResources().getColor(R.color.test_color_blue)));
Và đây là kết quả:
trước:
Sau:
Một số cách tiêu đề thanh công cụ vẫn có cùng màu nền như trước.
đây là thanh công cụ của tôi xml:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/Theme.Toolbar">
Và đây là Theme:
<style name="Theme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:maxHeight">@dimen/abc_action_bar_default_height_material</item>
<item name="android:background">@color/primary</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@android:color/white</item>
<item name="titleTextAppearance">@style/Theme.Toolbar.Title</item>
</style>
Bạn đã áp dụng bất kỳ kiểu tùy chỉnh nào cho thanh tác vụ trong tệp styles.xml, có thể một số trong số đó là mâu thuẫn. – Harry
đăng bố cục xml của bạn, vui lòng –
@DavidJhons tôi đã đăng chi tiết mới về các câu hỏi – EkKoZ