Search code examples
androidandroid-layoutnavigation-drawerslidingdrawer

How to change the color of the main bar?


I'm learning to make the sliding menu ( drawer )

I've tried using various solutions of other friends in the group , but none of them worked.

I can change all the colors of the layout in my app , except the color of the top bar (main ) . I would put the color # 1674d3 as the bottom of the main bar. Any friend can help me solve this?

My coding was based on this tutorial: Click here!

https://i.sstatic.net/KzueP.png


Solution

  • For API level 11 or greater or Lesser API level

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                 // only for HoneyComb and newer versions
                ActionBar bar = getActionBar();
    
                // title;
                bar.setTitle(Html.fromHtml("<font color='#000000'>Home</font>"));
    
                //Rgb for yellow.
                bar.setBackgroundDrawable(new ColorDrawable(Color.rgb(255,215,0)));
            }