ways to add 18dpx18dp size image right of title in collapsing toolbar layout? but not in toolbar

烈酒焚心 提交于 2019-12-11 22:40:52

问题


  • I want to put an icon right to title in collapsing tool bar, shown as below

  • but After collapsing i don't want it to show in tool bar.
  • i want to hide after collapsing.

  • i have done some thing. using

    collapsingToolbarLayout.setTitle(item.getName()); collapsingToolbarLayout.setForeground(getResources().getDrawable(R.drawable.ic_photo_library_white_24dp));

  • which look like this.

  • i am still trying to adjust that image.

  • but i want to hide that image after collapsing. bez it looks like this.

here is my java code.

private void setToolbar(Product item) {
((AppCompatActivity) getActivity()).setSupportActionBar((productToolBar));

ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
actionBar.setTitle("");
productToolBar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        getActivity().onBackPressed();
    }
});
collapsingToolbarLayout.setTitle(item.getName());
collapsingToolbarLayout.setForeground(getResources().getDrawable(R.drawable.ic_photo_library_white_24dp));
collapsingToolbarLayout.set
}

and my xml file.

<android.support.design.widget.CoordinatorLayout
android:id="@+id/product_detail_main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:apptools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/product_detail_appBar_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/detail_product_collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foregroundGravity="bottom|right"
    android:foregroundTintMode="add"
    android:clipToPadding="true"
    app:contentScrim="?attr/colorPrimary"
    app:expandedTitleMarginStart="@dimen/space_xxlarge"
    app:layout_scrollFlags="scroll|exitUntilCollapsed">

    <ImageView
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/image"
        android:fitsSystemWindows="true"
        android:scaleType="centerCrop"
        app:layout_collapseMode="parallax"
        app:layout_collapseParallaxMultiplier="0.7"/>

    <android.support.v7.widget.Toolbar
        android:id="@+id/product_toolBar_title"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:fitsSystemWindows="true"
        app:layout_collapseMode="pin"
        app:navigationIcon="@drawable/ic_arrow_back_white_24dp"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
 ........
<android.support.design.widget.CoordinatorLayout
  • Thanks in advance. ^_^

回答1:


i got the solution its an issue.

  • CollapsingToolbarLayout child views not shown in devices< Android L 5.1 including 5.0

here is the link

  • https://code.google.com/p/android/issues/detail?id=177738&can=1&q=CollapsingToolbarLayout&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars


来源:https://stackoverflow.com/questions/31354087/ways-to-add-18dpx18dp-size-image-right-of-title-in-collapsing-toolbar-layout-bu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!