Action Bar increased space between Title and Icon

397 Views Asked by At

I'm setting Action Bar for my app's ChatActivity but space between Icon and Title is so much that title is not visible

Here is my code

ab.setDisplayHomeAsUpEnabled(true);
ab.setDisplayShowHomeEnabled(true);
ab.setLogo(R.drawable.profile_default);
ab.setDisplayUseLogoEnabled(true);
ab.setTitle("Hello");
ab.setDisplayShowTitleEnabled(true);

I dont know why there is much spacing between elements. Please help me fix this.

edit 1: Here is part of my activity layout xml:

<android.support.v7.widget.Toolbar
        android:id="@+id/contacts_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
1

There are 1 best solutions below

2
Chetan Mahajan On

try this,

<RelativeLayout
        android:id="@+id/relative1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorToolbar"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:titleTextColor="#000000"
       >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center">

        <Button
            android:id="@+id/back"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/ic_keyboard_arrow_left_black_24dp" />


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Your Title"
            android:textColor="@color/colorAccent"
            android:textStyle="bold"
            android:textSize="20sp"
            android:gravity="center"/>

        <Button
            android:id="@+id/logout"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:layout_marginEnd="18dp"
            android:background="@drawable/logout"
            />
        </RelativeLayout>

Hope this is helpful.