Change action bar color in android

前端 未结 9 1766
北海茫月
北海茫月 2020-12-05 19:28

I am using the app theme Theme.Black in my app. In this theme the action bar is gray. How I can change color of my action bar? This is my attempt:



        
9条回答
  •  有刺的猬
    2020-12-05 20:14

    onclick buttons c2 to fetch and change the color of action bar and notification bar according to button's background, hope this helps

    int color = c2.getBackground()).getColor();
    int colorlighter = -color * 40 / 100 + color;
    getWindow().setNavigationBarColor(colorlighter);
    getWindow().setStatusBarColor(colorlighter);
    ActionBar bar = getSupportActionBar();
    bar.setBackgroundDrawable(new ColorDrawable(color));
    

    colorlighter is used to set color of notification bar a little lighter than action bar
    color is the background color of button c2, according to which we change our color.

提交回复
热议问题