VIN*_*VIN 11 android android-collapsingtoolbarlayout android-appbarlayout
我想用折叠的collapsingToolbar加载一个片段(即以非扩展形式).当我设置collapsingToolbar的标题而不改变appbarLayout布局参数时,标题设置正确,我可以看到标题.
问题是,我还需要更改appBarLayout布局参数以防止collapsingToolbar扩展(即我希望它看起来和行为像这个特定片段的常规非折叠工具栏).但是,这样做会使标题不再出现.
我尝试了什么: 我尝试过在这些页面上列出的解决方案无济于事:
collapsingToolbarLayout.setTitleEnabled(true); 似乎没有任何影响MainActivity.java 我相信我已将问题隔离到这些行,但我不知道如何解决它.
collapsingToolbarLayout.setTitle("All Recent"); // works
appBarLayout.setExpanded(false, true); // works
// However, after adding the following lines, the above no longer works and the title does not appear in the toolbar
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams)appBarLayout.getLayoutParams();
lp.height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 80, getResources().getDisplayMetrics());
appBarLayout.setLayoutParams(lp);
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:adjustViewBounds="true" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/drawer_item_locate_events" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/frame_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
android:src="@mipmap/ic_add_a_photo"
app:layout_anchor="@+id/appbar_layout"
app:layout_anchorGravity="bottom|right|end" />
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
VIN*_*VIN 43
我能够使用@DanielPersson提供的以下答案来解决这个问题:如何在CollapsingToolbarLayout中的工具栏中固定标题:
collapsingToolbarLayout.setTitleEnabled(false);
toolbar.setTitle("My Title");
Run Code Online (Sandbox Code Playgroud)
通过调用setTitleEnabled(false);,标题出现在工具栏中.
| 归档时间: |
|
| 查看次数: |
12504 次 |
| 最近记录: |