Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce left and bottom space from toolbar title in collapsing action bar android?

enter image description here enter image description here

I need to reduce left and bottom space from toolbar title in collapsing action bar. I need to do something like whats app. Here is my code. Thanks for help.

  <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        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:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/img_profile"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/speaker1"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"
                app:layout_collapseMode="pin" />

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

    </android.support.design.widget.AppBarLayout>
like image 918
Jaimin Prajapati Avatar asked Oct 29 '22 04:10

Jaimin Prajapati


1 Answers

add this below in your activity where you are setting the title

 mBinding.collapseToolbar.setExpandedTitleMarginBottom((int) getResources().getDimension(R.dimen.contact_info_expanded_title_margin));
 mBinding.collapseToolbar.setExpandedTitleMarginStart((int) getResources().getDimension(R.dimen.contact_info_expanded_title_margin));

mBinding.collapseToolbar.setTitle("Toolbar title");
like image 118
Padma Kumar Avatar answered Nov 09 '22 11:11

Padma Kumar