Search code examples
androidandroid-actionbar

How to add images on ActionBar in android


I want to make a action bar in android on which i want to add three Image buttons. But i don't know how to add image buttons on action bar i have no idea about it. I want to add one image button on left side of action bar and one image button on right side and one image view in center. I don't know how to make it possible.


Solution

  • If you are using toolbar, then you can do like this.

         <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">
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="true"
                        android:src="@mipmap/ic_launcher" />
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:src="@mipmap/ic_launcher" />
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentEnd="true"
                        android:layout_alignParentRight="true"
                        android:src="@mipmap/ic_launcher" />
    
                </RelativeLayout>
    
            </android.support.v7.widget.Toolbar>