Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change background color of action bar without increasing min sdk?

As we know, a colored background of action bar permitted in sdk level 11, watch this. But there are some applications with colored action bar that have min sdk lower than 11. For example Whatsapp has green action bar but has min sdk:7 WhatsApp FAQ, or the Telegram application has min sdk:8 Telegram FAQ, but has blue action bar.

How these applications work? And how I can do this?

android.app.ActionBar actionBar = (android.app.ActionBar) getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
View mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_main, null);
actionBar.setCustomView(mActionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

This code requires minSdk = 11, for getActionBar(). Please help me.

like image 943
Seyyed Mahmood Ahmadi Avatar asked Jul 31 '16 16:07

Seyyed Mahmood Ahmadi


1 Answers

the Toolbar (new name for the ActionBar introduced in Lollipop) is just a normal View.

Link: https://developer.android.com/reference/android/support/v7/widget/Toolbar.html

you just set it's background like any other view.

// java
toolbar.setBackgroundColor(int color);
// or 
toolbar.setBackgroundResource(int resId);

// or XML
android:background="@drawable/toolbarBackground"
like image 151
Budius Avatar answered Oct 21 '22 23:10

Budius