-1

Hey i want to change my statusbar color i set in my styles.xml and v21/styles.xml this:

    <style name="AppTheme" parent="Theme.AppCompat">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/colorPrimaryText</item>
    <item name="android:windowBackground">@color/windowBackground</item>


    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowActionBarOverlay">false</item>



</style>

and in my main activity this:

        Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(myToolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setElevation(0);
    getSupportActionBar().getThemedContext();

    Window window = this.getWindow();

    // clear FLAG_TRANSLUCENT_STATUS flag:
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

    // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

    // finally change the color
    window.setStatusBarColor(this.getResources().getColor(R.color.colorPrimaryDark));

but it dosent work... can someone help? I use AppCompact in my mainAcitvity

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
developKinberg
  • 363
  • 4
  • 18

2 Answers2

0

Call this method to change color from Kitkat bellow Kitkat works normally

//Utils.java
 public static boolean hasKitKat()
    {
        return Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT;
    }

//Your Activity
      public void applyKitKatTranslucency(int color) {
            if (Utils.hasKitKat()) {
                if (mTintManager == null)
                    mTintManager = new SystemBarTintManager(this);
                mTintManager.setStatusBarTintEnabled(true);
                mTintManager.setStatusBarTintColor(color);

            }
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
        }
Suhas Bachewar
  • 1,230
  • 7
  • 21
0

Try the below.

 window.setStatusBarColor(this.getResources().getColor(R.color.statusbar));

First create a new color within your color resource file. You need to define the colour inside your colour.xml resource file.

<item name="statusbar" type="color">#FFF</item> 

I hope this helps..

Maddie_J
  • 171
  • 3
  • 15