Java 我想在隐藏工具栏上滑动,但它';这是不对的
我想在隐藏工具栏上滑动,但随后我面临一个错误!Java 我想在隐藏工具栏上滑动,但它';这是不对的,java,android,Java,Android,我想在隐藏工具栏上滑动,但随后我面临一个错误!(我想上滑隐藏工具栏然后出错了。) android.view.InflateException:Binary XML file line #8: Binary XML file line #8: Error inflating class android.support.design.widget.AppBarLayout Caused by: android.view.InflateException: Binary XML file line
(我想上滑隐藏工具栏然后出错了。)代码>
android.view.InflateException:Binary XML file line #8: Binary XML file line #8: Error inflating class android.support.design.widget.AppBarLayout
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.design.widget.AppBarLayout
这是我的布局代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:fitsSystemWindows="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.Toolbar
android:id="@+id/tuijian_toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_scrollFlags="scroll|enterAlways">
<TextView
android:id="@+id/ToolBar_Title"
android:layout_width="80dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:text="测试标题"
android:textColor="@color/black"
android:textSize="18sp"
/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<..recyclerview.../>
</android.support.constraint.ConstraintLayout>
谢谢
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/id_toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|exitUntilCollapsed" />
</android.support.design.widget.AppBarLayout>
我不知道你的代码有什么问题…请参考此链接
我希望这能对您有所帮助。您的工具栏的父布局是AppBarLayout。因此,您不能在工具栏中使用约束。因此,请删除约束。
您的工具栏应如下所示:
<android.support.v7.widget.Toolbar
android:id="@+id/tuijian_toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/white"
app:layout_scrollFlags="scroll|enterAlways">
注意:如果要设置标题,不必使用TextView。您可以在工具栏中使用标题属性。或者在“活动”中以编程方式将其设置为“setTitle();”我将ConstraintLayout视为根布局,并且我的活动扩展了AppCompatActivity,然后它就工作了!ConstraintLayout>AppBarLayout>toolbar