所以我在我的应用程序中添加了一个底部导航视图,但有一个问题,我希望我的底部导航视图的背景是透明的(目前是黑色的),即我希望它显示相对布局的背景部分(包含btmnav),它覆盖。我希望我的底部导航视图的背景是透明的(目前是黑色的),也就是说,我希望它能显示出相对布局(包含btmnav)的背景中它所覆盖的部分,我在某个地方读到过,它默认是这样做的,我需要做的就是给相对布局一个背景,这样就可以了......但当我这样做时,底部导航视图的背景仍然是黑色的。
菜单资源文件。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/live"
android:icon="@drawable/ic_live_tv_black_24dp"
android:title="Live"/>
<item
android:id="@+id/squad"
android:icon="@drawable/ic_team_squad_black_24dp"
android:title="Squad"/>
<item
android:id="@+id/schedule"
android:icon="@drawable/ic_schedule_black_24dp"
android:title="Schedule"/>
<item
android:id="@+id/feed"
android:icon="@drawable/ic_rss_feed_black_24dp"
android:title="Feed"/>
</menu>
布局文件中的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/btmnav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemTextColor="#fff3CD70"
app:itemIconTint="#fff3CD70"
app:menu="@menu/bottom_navigation" />
</RelativeLayout>
将 "btmnav "的背景设置为具有透明alpha通道的颜色。
添加到你的BottonNavigationView android:background="#00ffffff"
你也可以设置一个主题并在那里设置。
android:theme="@style/NavigationTheme"
Styles.xml
<style name="NavigationTheme" parent="AppTheme">
<item name="itemIconTint">@android:color/white</item>
<item name="itemTextColor">@android:color/white</item>
<item name="android:background">#00ffffff</item>
</style>
我在用这条线。
BottomNavigationView navView = findViewById(R.id.nav_view);
navView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.transparent));
这是我的 计划