Java 设置Recycleviewer背景时隐藏工具栏
当我在RecyclerView上设置背景参数时,它会隐藏工具栏 很简单,但我不知道如何修复它 activity_main.xml:Java 设置Recycleviewer背景时隐藏工具栏,java,android,xml,android-recyclerview,toolbar,Java,Android,Xml,Android Recyclerview,Toolbar,当我在RecyclerView上设置背景参数时,它会隐藏工具栏 很简单,但我不知道如何修复它 activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" androi
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="@android:color/darker_gray"
tools:context="los.printers.MainActivity"
app:theme="@style/Theme.MyTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/tb_main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<RelativeLayout
android:id="@+id/rl_fragment_container"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
fragment_printer.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="los.printers.fragment_printer">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_List"
android:scrollbars="vertical"
android:paddingTop="?attr/actionBarSize"
android:background="@color/colorTextIcons"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
填充在RecyclerView中工作正常,但工具栏不会显示。更新
活动\u main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="@android:color/darker_gray"
tools:context="los.printers.MainActivity"
app:theme="@style/Theme.MyTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/tb_main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<RelativeLayout
android:id="@+id/rl_fragment_container"
android:layout_below="@+id/tb_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
您的
rl\u fragment\u容器
绘制在工具栏顶部
但我认为你知道这一点,因为你在片段中添加了填充
填充将以相同的大小绘制视图并应用于其内容,而边距将位于视图边界之外,从而使整个视图变小。如果你画背景,这很重要
如前所述,您的片段位于工具栏的顶部,您的recyclerview将填充整个片段并在顶部绘制背景
你现在可以
rl\u fragment\u容器
移动到xml中的工具栏之前->这将在工具栏下方绘制它android:layout_down=“@+id/tb_main”
在工具栏下方布局rl_fragment_容器
,然后移除填充和边距在工具栏下方创建recylerview并删除android:layout\u alignParentTop=“true”行请参见下面的答案