隐藏工具栏布局线

时间:2019-11-01 14:37:42

标签: android xml

我有一个UI设计可以创建工具栏浸入recyclerview的位置。 我已经创建了设计,但是布局的线条在设备上仍然可见,而在仿真器中似乎正确。如何在recyclerview中合并布局线。

下面是模拟器的屏幕截图

enter image description here

及以下是我设备的屏幕截图 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 个答案:

答案 0 :(得分:1)

最简洁的答案和最简单的删除隐藏工具栏布局行/分隔线的方法是在AppTheme样式或您为活动声明的任何主题样式内的style.xml文件中添加此行:

<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

答案 1 :(得分:0)

该行是阴影,由工具栏的海拔高度引起。高程仅在运行Lollipop或更高版本的设备上自动发生,并且布局预览通常不显示阴影。

尝试将此属性添加到工具栏的XML中以删除高程(并因此去除阴影):

android:elevation="0dp"