我想制作自定义工具栏并在CollapsingToolbarLayout中显示文本。当我使用下面的代码时,只是我的标题显示正确!
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:background="@drawable/img_back"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@color/app_orange_color"
app:expandedTitleGravity="center"
app:expandedTitleMarginTop="-40dp"
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Headline"
app:layout_scrollFlags="scroll|exitUntilCollapsed" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/height_toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
但是当我自定义下面代码的工具栏时,将隐藏折叠工具栏的标题:
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:background="@drawable/img_back"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@color/app_orange_color"
app:expandedTitleGravity="center"
app:expandedTitleMarginTop="-40dp"
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Headline"
app:layout_scrollFlags="scroll|exitUntilCollapsed" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/height_toolbar"
android:layout_gravity="end"
android:contentInsetEnd="0dp"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
android:gravity="end"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:gravity="left">
<ImageView
android:id="@+id/imgCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="10dp"
android:src="@mipmap/ic_local_grocery_store_white_24dp" />
<com.example.shop.widgets.CustomBoldTextview
android:id="@+id/txtCardBadge"
android:layout_width="19dp"
android:layout_height="19dp"
android:layout_alignRight="@id/imgCard"
android:layout_alignTop="@id/imgCard"
android:layout_margin="2dp"
android:background="@drawable/drawable_circle_card_badge"
android:gravity="center"
android:text="10"
android:textColor="@color/app_white_color"
android:textSize="11sp" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
我需要的是在折叠工具栏的中间显示我的自定义工具栏和显示标题。 我该怎么办?