问题是它在底部导航视图中显示白色背景,但我希望它具有透明性。为什么要这样做?
所以看起来我的 android 应用程序:
这是我的代码:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemRippleColor="#00931E30"
android:outlineAmbientShadowColor="#00931E30"
android:outlineSpotShadowColor="#00931E30"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:menu="@menu/bottom_menu"
tools:visibility="visible">
我也试过用这个设置底部导航视图的背景:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/transparent" />
</shape>
以及通过编程:
bottomNavigationView.background = ColorDrawable(Color.TRANSPARENT)
bottomNavigationView.itemBackgroundResource = R.drawable.transparent
我不知道问题出在哪里,如果有人知道解决方案,我将不胜感激。
活动的整个 XML 如下所示:
<?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=".ui.MainActivity">
<ImageView
android:id="@+id/imgBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher_track"
tools:ignore="MissingConstraints" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemRippleColor="#AD931E30"
android:background="#028C8C8C"
android:outlineAmbientShadowColor="#00931E30"
android:elevation="10dp"
android:layout_alignParentBottom= "true"
android:visibility="visible"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintVertical_bias="1.0"
app:menu="@menu/bottom_menu"
tools:visibility="visible"
>
<com.google.android.material.tabs.TabItem
android:background="#00424242"
android:id="@+id/go_to_home"
android:layout_width="100dp"
android:layout_height="70dp"
android:onClick="goToHome"
android:text="schmutz">
</com.google.android.material.tabs.TabItem>
<com.google.android.material.tabs.TabItem
android:id="@+id/go_to_dash"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginLeft="100dp"
android:onClick="goToDash"
android:text="schmutz" />
<com.google.android.material.tabs.TabItem
android:id="@+id/go_to_not"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginLeft="180dp"
android:onClick="goToNotification"
android:text="schmutz" />
<com.google.android.material.tabs.TabItem
android:id="@+id/go_to_profile"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginLeft="260dp"
android:text="schmutz"
android:onClick="goToProfile"/>
</com.google.android.material.bottomnavigation.BottomNavigationView>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#00B8B8B8"
app:tabIndicatorHeight="3dp"
app:tabMode="fixed"
tools:ignore="MissingConstraints" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="675dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="?attr/actionBarSize"
android:layout_marginBottom="?attr/actionBarSize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="1.0" />
<fragment
android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="1000dp"
android:layout_marginBottom="56dp"
app:defaultNavHost="true"
app:flow_horizontalAlign="center"
app:flow_verticalAlign="center"
app:navGraph="@navigation/my_nav"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="278dp">
</fragment>
</RelativeLayout>