繁体   English   中英

Android Kotlin; 尽管设置了背景透明,为什么它从底部导航视图显示白色背景?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM