Skip to content Skip to sidebar Skip to footer

How To Reduce The Space Between Icon And Home Up Key In Custom Action Bar In Android

I'm using custom action bar in AppCompatActivity. I give the my code below as well as the pitcher. i tried all solution available in stack over flow. But till i can't fix this issu

Solution 1:

you can use toolbar property for this

app:contentInsetLeft="0dp"app:contentInsetStart="0dp"app:contentInsetStartWithNavigation="0dp"

like this use in toolbar

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetStartWithNavigation="0dp" />

Solution 2:

if you are using Toolbar then add the following line in Toolbar in xml

app:contentInsetStart="0dp"

Update:

You mean you want toolbar like Whatsapp. but it's not done by using App-compat Support Library Toolbar you have to use Custom Action Bar.

You can get the following result as shown in the Picture below

enter image description here

by using following code.

activity.xml

<android.support.design.widget.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content" ><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar_chats"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"app:popupTheme="@style/ThemeOverlay.AppCompat.Light"><includelayout="@layout/custom_toolbar"/></android.support.v7.widget.Toolbar></android.support.design.widget.AppBarLayout>

custom_toolbar.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:background="?attr/selectableItemBackgroundBorderless"android:layout_width="fill_parent"android:layout_height="?actionBarSize"
><!-- android:background="?attr/selectableItemBackgroundBorderless" will cause this Custom View to make ripple effect --><LinearLayoutandroid:id="@+id/conversation_image"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_centerVertical="true"android:contentDescription="@string/abc_action_bar_up_description"android:orientation="horizontal"><ImageViewandroid:id="@+id/conversation_contact_photo"android:layout_width="35.0dip"android:layout_height="35.0dip"android:src="@drawable/icon"android:scaleType="fitCenter" /></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toRightOf="@id/conversation_image"android:orientation="vertical"android:paddingBottom="2.0dip"android:paddingLeft="4.0dip"android:paddingRight="0.0dip"android:paddingTop="0.0dip" ><TextViewandroid:id="@+id/action_bar_title_1"android:layout_width="wrap_content"android:layout_height="0dp"android:layout_gravity="center_vertical"android:layout_marginLeft="6dp"android:layout_weight="0.6"android:ellipsize="end"android:gravity="center_vertical"android:maxLines="1"android:textSize="18sp"android:text="shanraisshan"android:textStyle="bold" /><TextViewandroid:id="@+id/action_bar_title_2"android:layout_width="wrap_content"android:layout_height="0dp"android:layout_marginLeft="6dp"android:layout_weight="0.4"android:ellipsize="end"android:text="last seen 1 hour ago"android:maxLines="1"android:textSize="12sp" /></LinearLayout>

YourActivity.java

finalToolbartoolbar= (Toolbar) findViewById(R.id.toolbar_chats);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setOnClickListener(newView.OnClickListener() {
    @OverridepublicvoidonClick(View v) {
        Log.e("Toolbar","Clicked");
    }
});

Post a Comment for "How To Reduce The Space Between Icon And Home Up Key In Custom Action Bar In Android"