nitinku5021a
nitinku5021a

Reputation: 129

How to change Toolbar Color with different views?

I am setting up my Toolbar in my main activity and trying to change the background color with different fragments. So basically, I am trying to access the Toolbar object inside fragment and set different background color. Few things which I have tried to do is :

Access toolbar like: ((ActionBarActivity)getActivity()).getSupportActionBar().setBackgroundColor(XXX);

But I am unable to access the setBackgroundColor function inside fragment. It is perfectly working inside the Main Activity.

Upvotes: 2

Views: 5117

Answers (2)

Maheshwar Ligade
Maheshwar Ligade

Reputation: 6855

It is very easy to change the ToolBar, Actionbar color.

ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));

or

   ActionBar bar = getSupportActionBar();
    bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));

Upvotes: 2

Chirag Savsani
Chirag Savsani

Reputation: 6140

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));

or

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));

Have a look This or This

Upvotes: 4

Related Questions