5

How I can change background color of titlebar without using theme. tnks in Android.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
Friz14
  • 278
  • 3
  • 11

3 Answers3

4

Try with the following code

View titleView = getWindow().findViewById(android.R.id.titlebar);
    if (titleView != null) {
      ViewParent parent = titleView.getParent();
      if (parent != null && (parent instanceof View)) {
        View parentView = (View)parent;
        parentView.setBackgroundColor(Color.RED);
      }
    }
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
  • 1
    @Friz14 Where did you find it? I ran into [a similar problem](http://stackoverflow.com/q/11263829/869501) and I can't find that `android.R.id.titlebar`. Thanks +1. – ateiob Jun 29 '12 at 14:54
  • I am using title instead of titlebar, and i am not able to change color of titlebar.. do i need to set anything else to make it work? – Vikas Gupta May 23 '13 at 05:24
0

ActionBar bar = getActionBar(); bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.material_blue_gray1)));

Shubham Jain
  • 2,365
  • 2
  • 17
  • 29
-1

I think this other dicussion will be helpful to you:

Set title background color

Community
  • 1
  • 1
kikoso
  • 673
  • 1
  • 6
  • 17