隐藏工具栏布局线。

3
我需要创建一个UI设计,其中工具栏嵌入到recyclerview中。我已经创建了设计,但是布局的线在设备上仍然可见,而在模拟器中看起来是正确的。我该如何将布局线合并到recyclerview中。
下面是来自模拟器的屏幕截图。

enter image description here

以下是来自我的设备的截图 在此输入图片描述

<?xml version="1.0" encoding="utf-8"?>

<androidx.coordinatorlayout.widget.CoordinatorLayout 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">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:background="@android:color/transparent"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:elevation="0dp"
            android:background="@android:color/transparent"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_weight="100"
            app:layout_scrollFlags="scroll|enterAlways">

            <LinearLayout
                android:layout_width="match_parent"
                android:weightSum="100"
                android:background="@android:color/transparent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/toolbar_title"
                    android:layout_width="0dp"
                    android:gravity="center"
                    android:layout_weight="80"
                    android:layout_height="match_parent"
                    android:text="@string/app_name"
                    android:textColor="@android:color/black"
                    android:textSize="25sp"
                    android:textStyle="bold" />

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="60dp"

                    android:layout_weight="20"
                    android:layout_gravity="right"
                    android:src="@drawable/ic_add_black_24dp" />
            </LinearLayout>
        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:background="@android:color/transparent"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
2个回答

1
那条线是阴影,由工具栏的elevation引起。仅在运行Lollipop或更高版本的设备上自动发生高度,并且布局预览通常不显示阴影。尝试将此属性添加到您的工具栏XML中以移除高度(因此也会移除阴影):
android:elevation="0dp"

1
在你的style.xml文件中,添加以下代码到AppTheme样式或者你为activity声明的任何主题样式中,即可最简洁地移除ToolBar Layout线条/分割线:
<item name="android:showDividers">none</item>

那么你的代码应该长这个样子。
 <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    ...
    <item name="android:showDividers">none</item>
    <!-- This line is not compulsory -->
    <item name="actionBarDivider">@android:color/transparent</item>
     <!-- This line is not compulsory -->
    ...
</style>

我希望这能有所帮助。虽然对我有效,但你需要查看以下典型示例的屏幕截图: enter image description here

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接