简体   繁体   中英

Change Toolbar Background Color and Title

I am trying to change the background and title of the toolbar widget set as actionbar .

final Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);

It want it like the Google Play Store App.
Apps -> Grey (background) and "Apps" (title)
My Apps -> Green (background) and "My Apps" (title)
so i tried already to change the title with

Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.my_awesome_toolbar);
toolbar.setTitle("Jiji");

toolbar toolbar = (Toolbar) rootView.findViewById(R.id.my_awesome_toolbar);
toolbar.setTitle("Jiji");
getActivity().setActionBar(toolbar); // error: incompatible types: android.support.v7.widget.Toolbar cannot be converted to android.widget.Toolbar

getActivity.setTitle("ododo") //works for a short moment

for the background there is just a method called setBackgroundDrawable marked as `deprecated``but the method don´t work for me :-( maybe releated https://code.google.com/p/android/issues/detail?id=78471&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

any idea is welcome :-)

I have found the solution myself
first change Activity to ActionBarActivity then you can work with getSupportActionBar() for the toolbar background like:

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#f44336")));

and for the statusbar you can work with setStatusBarColor like:

if (android.os.Build.VERSION.SDK_INT >= 21) {
    getWindow().setStatusBarColor(Color.parseColor("#e53935"));
}

cheers ternes3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM