android页面标题不见了,android - 展开时,CollapsingToolbarLayout标题消失了
我有这种平静的XML。android:layout_width="match_parent"android:layout_height="match_parent"android:minHeight="?attr/actionBarSize"android:fitsSystemWindows="true"app:toolbarId="@+id/toolbar"android:id="@+id/co
我有这种平静的XML。
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:toolbarId="@+id/toolbar"
android:id="@+id/collapsing"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
它根本不显示标题。(下图)
但当折叠工具栏布局有点折叠时,标题会显示出来。
我在create方法中设置了活动标题。
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
CollapsingToolbarLayout layout = (CollapsingToolbarLayout) findViewById(R.id.collapsing);
layout.setTitle(toolbar.getTitle());
layout.invalidate();
完整XML:
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:paddingBottom="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="match_parent"/>
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:toolbarId="@+id/toolbar"
android:id="@+id/collapsing"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
android:id="@+id/custom_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="invisible"/>
android:id="@+id/drawer_linear"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical" >
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:background="@color/drawer_grey"
android:divider="@drawable/drawer_divider"
android:scrollbars="none"
android:dividerHeight="1px" />
有什么办法让标题一直出现吗?
最佳答案
我有同样的问题,经过几个小时的搜索,我找到了一个解决方案,并想与你分享。
使用com.android.support:design:23.1.0
您的布局应该如下所示:
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap />
我希望我能帮助别人。
溶液来自thispost。
更多推荐
所有评论(0)