2016-04-14 21 views
-1

Hey ich will meine statusbar Farbe ändern ich dies in meiner styles.xml und v21/styles.xml gesetzt:Wie die Statusfarbe ändern

<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> 

und in meiner Haupttätigkeit dieses:

 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)); 

aber es dosent Arbeit ... kann jemand helfen? Ich benutze AppCompact in meinem mainAcitvity

+0

auf dem hilft Gerät, das Sie testen ?? –

+0

Ich Test auf einem Huawei mit der Android-Version 5.1.1 – developKinberg

+0

@developKinberg siehe meine Antwort unten. –

Antwort

0

Rufen Sie diese Methode verfärben von Kitkat Kitkat Balg arbeitet normalerweise

//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)); 
     } 
0

die folgenden Versuchen.

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

Erstellen Sie zunächst eine neue Farbe in Ihrer Farbressourcendatei. Sie müssen die Farbe in Ihrer colour.xml-Ressourcendatei definieren.

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

Ich hoffe, das ..