Android 使底部导航视图背景透明
因此,我在我的应用程序中添加了一个底部导航视图,但存在一个问题。我希望我的底部导航视图的背景是透明的当前为黑色,即我希望它显示包含其覆盖的btmnav的相对布局的背景部分。我在某个地方读到过,默认情况下它会这样做,我需要做的是给相对布局一个背景,它会工作…但当我这样做时,底部导航视图的背景仍为黑色 菜单资源文件:Android 使底部导航视图背景透明,android,androidx,bottomnavigationview,Android,Androidx,Bottomnavigationview,因此,我在我的应用程序中添加了一个底部导航视图,但存在一个问题。我希望我的底部导航视图的背景是透明的当前为黑色,即我希望它显示包含其覆盖的btmnav的相对布局的背景部分。我在某个地方读到过,默认情况下它会这样做,我需要做的是给相对布局一个背景,它会工作…但当我这样做时,底部导航视图的背景仍为黑色 菜单资源文件: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.
<?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通道的颜色 添加到您的BottonAvigationView 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>
将“btmnav”的背景设置为具有透明alpha通道的颜色 添加到您的BottonAvigationView 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));
这是我的我在用这行:
BottomNavigationView navView = findViewById(R.id.nav_view);
navView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.transparent));
这是我的第1步:创建一个带有透明矩形的可绘制文件
res\drawable\transparent\u rect.xml
步骤1:创建具有透明矩形的可绘制文件
res\drawable\transparent\u rect.xml
注意:您应该使用alpha通道值以获得正确的透明度级别。00是完全透明的,但30-50将提供基本透明的外观,而aa ff将基本不透明/注意:您应该使用alpha通道值以获得正确的透明度级别。00是完全透明的,但30-50将提供基本透明的外观,而aa ff将基本不透明/感谢您的回复,谢谢!。谢谢你的回复,非常感谢!。很好,这个答案对我有效。很好,这个答案对我有效。