设置完上面的代码没生效
时间: 2023-12-18 13:03:02 浏览: 63
如果以上代码设置后并没有生效,可能是因为您的设备系统版本过低。在 Android 5.0 及以上版本中,可以使用以上方式来设置底部导航栏颜色,但在 Android 4.4 及以下版本中,该方法不适用。
对于低版本 Android 系统,您可以尝试使用以下方法来设置底部导航栏颜色:
1. 使用 Java 代码设置
```java
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(Color.WHITE);
}
```
2. 使用 XML 布局设置
在 XML 布局文件中,可以通过设置 `android:navigationBarColor` 属性来改变底部导航栏颜色,如下所示:
```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
```
需要注意的是,这种方式只能改变底部导航栏的背景色,而无法改变其图标和文字颜色。如果需要改变图标和文字颜色,可以通过自定义底部导航栏来实现。
阅读全文
相关推荐


















