通过编程方式更改Galaxy S8导航栏颜色



由于Galaxy S8 home/back/近期按钮现在是软键,因此我只需要更改应用程序中的按钮的背颜色。

您的问题在棒棒糖及以上解决了,

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setNavigationBarColor(Color.YOUR_COLOR);
}

通过编程提出的问题正确回答了哪个dhruv patel

但是,对于任何偶然发现并想知道如何在XML中执行此操作的人,请从/Res/values-v21/styles.xml打开styles.xml(如果您的Minsdk小于21,否则Just/Res/values/styles.xml)以及在您在AndroidManifest中使用的主题(我在整个中使用'apptheme'),

androidmanifest.xml

    ...
    <application
        android:name=".MyApp"
        android:icon="@drawable/appicon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

在styles.xml中插入主题下的行

    <item name="android:navigationBarColor">@android:color/black</item>

并将颜色更改为您想要的任何东西,所以看起来像

style.xml

    <resources>
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
        <!-- Other items -->
        <item name="android:textColorHint">@color/hint_gray</item>
        <item name="android:buttonStyle">@style/RobotoButtonStyle</item>

        <item name="android:navigationBarColor">@android:color/black</item>
    </style>
    </resources>

如果您的Minsdk小于21,并且您没有Styles-V21设置,则可以在styles.xml和Android Studio的内置工具中插入订单项,将显示错误并帮助创建目录

最新更新