大家下午好
我已经研究了很长时间了,是时候寻求帮助了。
我有以下应用栏
<?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:id="@+id/app_bar_constrained"
android:layout_height="?android:attr/actionBarSize"
android:layout_width="match_parent"
android:background="@drawable/appbar_background_2020">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:elevation="0dp"
android:background="@drawable/appbar_background_2020"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@id/app_bar_constrained">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/app_bar_collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_2020"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Title" />
<TextView
android:id="@+id/toolbar_sub_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:text="Subtitle"
tools:visibility="visible" />
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadingEdge="horizontal"
android:fadingEdgeLength="24dp"
android:visibility="gone"
android:layout_marginStart="24dp"
android:layout_marginEnd="@24dp"
android:elevation="0dp"
android:background="@drawable/appbar_background_2020"
app:tabBackground="?attr/selectableItemBackground"
app:tabGravity="start"
app:tabIndicator="@drawable/tab_indicator"
app:tabIndicatorColor="@color/colorPrimary"
app:tabIndicatorHeight="1dp"
app:tabMode="scrollable"
app:tabPaddingEnd="2dp"
app:tabPaddingStart="2dp"
app:tabRippleColor="@color/colorAccent"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextAppearance="@style/Widget.AppCompat.Light.ActionBar.TabBar"
app:tabTextColor="@color/colorPrimary"
tools:layout_conversion_absoluteHeight="48dp"
tools:layout_conversion_absoluteWidth="0dp" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
布局呈现在工具栏的右下角和左下角,背景是弯曲和剪裁的:
我之前通过使用 ConstraintLayout 而不是 AppBar 摆脱了这个问题,但这不适用于我们热衷于使用的 CoordinatorLayout 的动画。
请注意:出于公司考虑,我不得不更改上述代码示例中的颜色。
编辑:在回答以下问题时,背景文件是
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="24dp"
android:bottomRightRadius="24dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<solid android:color="@color/white" />
最佳答案
问题是因为您在 AppBarLayout 中使用的是 android:elevation="0dp" 而不是 app:elevation="0dp"。
还在您的 Activity 中添加以下代码:
findViewById(R.id.campfire_app_bar).bringToFront();
关于android - 为什么 AppBar 会在我的应用栏背景中添加方 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65318152/