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

Change Galaxy S8 Navigation Bar Color Programmatically

由于 galaxy s8 home/back/recent 按钮现在是软键,所以我只需要在我的应用程序中更改按钮的背景颜色。

您的问题已在 Lollipop 及以上版本中解决,

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,否则只是 /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>

然后将颜色更改为您想要的任何颜色,使其看起来像

styles.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 的内置工具将显示错误并帮助创建目录