[英]Android kotlin - Activity with black transparent background and SearchView with white background
[英]Android Kotlin; Why is it showing white background from Bottomnavigationview despite of setting background transparent?
問題是它在底部導航視圖中顯示白色背景,但我希望它具有透明性。 為什么要這樣做?
所以看起來我的 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>
試試這個代碼;
BottomNavigationView navView = findViewById(R.id.nav_view);
navView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.transparent));
能把整個活動的XML貼出來嗎? 我想看看哪些視圖是哪個視圖的子視圖,哪個視圖是哪個視圖的父視圖。
我不確定你為什么要讓它透明。 無論如何,通常會發生此問題,因為底部導航欄下沒有任何內容。 換句話說,它只涵蓋實際活動的背景。 我也不確定您是否希望導航欄浮在回收站視圖上。
嘗試使 recyclerview 的下約束到達屏幕的下邊緣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.