Ich möchte ein Fragment mit der ausgeblendeten collapsingToolbar laden (d. H. In seiner nicht-expandierten Form). Wenn ich den Titel der CollapsingToolbar einstelle, ohne die Layoutparameter von appbarLayout zu ändern, wird der Titel richtig gesetzt und ich kann den Titel sehen.collapsingToolbarLayout.setTitle (title) funktioniert nicht nach dem Ändern von appbarLayout
Das Problem ist, muss ich auch ändern Sie die appBarLayout Layout-Parameter zu verhindern, dass die CollapsingToolbar erweitern (d. H. Ich will es wie eine regelmäßige nicht kollabierende Symbolleiste für dieses bestimmte Fragment aussehen und verhalten). Dadurch wird der Titel jedoch nicht mehr angezeigt.
Was ich habe versucht: Ich habe versucht, Lösungen ohne Erfolg auf diesen Seiten aufgeführt:
- CollapsingToolbarLayout setTitle() not working anymore
- CollapsingToolbarLayout setTitle() does not update unless collapsed
collapsingToolbarLayout.setTitleEnabled(true);
scheint keine Wirkung zu haben
HauptActivity.java Ich glaube, ich habe das Problem zu diesen Zeilen isoliert, aber ich bin mir nicht sicher, wie ich es lösen soll.
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);
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" />
Titel nicht mehr angezeigt, nachdem würde geschätzt
Jede Hilfe appbarLayout-Parameter zu verändern.
Ich suchte ein paar Tage, um dieses Problem zu lösen, danke! Diese Lösung funktioniert perfekt. –
Arbeiten. Danke @Vinnie –
Es funktioniert nur für mich, wenn ich die Toolbar.app:title zuerst über xml auf einen nicht leeren Wert gesetzt habe. Danach funktioniert diese Lösung ... – IHeartAndroid