Search code examples
androidandroid-actionbar

How to position title to left and logo to right on Android ActionBar?


I'm very new to Android development, so I really need a helping hand. I would like to add a custom ActionBar to my app. I would like to have the title displayed on the left side, and the logo of my app on the right side. I have searched the net for solutions, but all I could reach is to have the title positioned to the left OR the logo positioned to the right, but could not get both be displayed. Anyone can help me how can I reach the desired display? I know Google suggest to have to logo on the left side, but this time I need to "overwrite" this "rule".


Solution

  • Try this following code for custom Toolbar

    <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorAccent"
            android:elevation="6dp">
    
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
    
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Tittle here"
                    android:textColor="#ffff"
                    android:layout_centerInParent="true"
                    android:textSize="23sp"
                    android:layout_alignParentLeft="true"/>
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:src="@mipmap/ic_launcher_round"/>
    
    
    
    
            </RelativeLayout>
    
        </android.support.v7.widget.Toolbar>
    

    Output:

    enter image description here

    I hope this will help you.