【发布时间】:2020-10-24 23:43:01
【问题描述】:
我有一个 AppBarLayout、LinearLayout 和一个 BottomNavigationView。我想在所有这些上方添加一个半透明的白色覆盖,但我不知道为什么我的 AppBarLayout 和 LinearLayout 上方会出现这种略带灰色的颜色。这是因为视图具有不同的高度吗?是否有可能在不改变它们的高度的情况下在我的其他两个布局上的 BottomNavigationView 上获得相同的效果?
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:background="@android:color/white">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:id="@+id/appBar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textColor="@android:color/black"
android:textSize="20sp"
android:layout_centerInParent="true"/>
<ImageButton
android:id="@+id/buttonMenu"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_menu"
android:layout_centerVertical="true"
android:layout_margin="16dp"/>
</RelativeLayout>
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/appBar"
app:layout_constraintBottom_toTopOf="@id/bottomNavigation"
android:id="@+id/linearLayoutContents">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lorem ipsum"
android:textSize="32sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_margin="24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:text="@string/content"
android:textColor="@android:color/darker_gray"
android:textSize="16sp"/>
</LinearLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/bottom_nav_menu"
android:id="@+id/bottomNavigation"
android:background="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/overlay"
android:background="#CCFFFFFF"
android:elevation="8dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
标签: android xml user-interface