-1

嘿,我想更改我在我的styles.xml和 v21/styles.xml 中设置的状态栏颜色:

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

在我的主要活动中:

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

但它不起作用......有人可以帮忙吗?我AppCompact在我的 mainAcitvity 中使用

4

2 回答 2

0

试试下面的。

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

首先在您的颜色资源文件中创建一种新颜色。您需要在 colour.xml 资源文件中定义颜色。

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

我希望这有帮助..

于 2016-04-14T14:35:41.420 回答
0

调用此方法从 Kitkat 更改颜色波纹管 Kitkat 正常工作

//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));
        }
于 2016-04-14T10:01:17.493 回答