Reputation: 6307
I'm changing toolbar color like this:
MainActivity.xml
<Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"></Toolbar>
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">#0000ff</item>
<item name="android:colorPrimaryDark">#ff0000</item>
<item name="android:textColorPrimary">#fff</item>
</style>
and MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setActionBar(toolbar);
I can change color colorPrimaryDark and textColorPrimary but can not change colorPrimary, why?
I can change toolbar color like this:
toolbar.setBackgroundColor(Color.parseColor("#0000ff"));
but cant change using style also why after removing setActionBar(toolbar); the text and title overflow menu gone why?
Upvotes: 1
Views: 3827
Reputation: 6307
From XML
android:background:"your color"
From code
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(Color.parse("your color"));
Upvotes: 2
Reputation: 1030
put these line
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));
Upvotes: 0