Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an icon at the end of Toolbar

Tags:

I want to set an icon at the the end of my Toolbar,which start another activity. My Toolbar portion

 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"                 xmlns:app="http://schemas.android.com/apk/res-auto"                 android:id="@+id/toolbar"                 android:layout_width="match_parent"                 android:layout_height="@dimen/abc_action_bar_default_height_material"                 android:background="#2B4AE0"                 app:theme="@style/ToolBarStyle">                  <TextView                     android:id="@+id/headerText"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:textAppearance="@android:style/TextAppearance.Theme"                     android:textColor="@android:color/white" />                  <RelativeLayout                     android:id="@+id/notification"                     android:layout_width="50dp"                     android:layout_height="match_parent"                     android:clickable="true"                     android:gravity="center" />                      <ImageView                         android:layout_width="25dp"                         android:layout_height="25dp"                          android:layout_centerHorizontal="true"                         android:layout_centerVertical="true"                         android:src="@drawable/bell_icon" />                 </RelativeLayout>             </android.support.v7.widget.Toolbar> 

I tried

android:layout_alignParentEnd="true" 

and setting margin left but it doesn't work correctly.

like image 819
shine_joseph Avatar asked Jan 13 '15 14:01

shine_joseph


People also ask

How do I change the End icon?

So to make it works, just copy and paste android:layout_gravity="end" to the ImageView /layout.

Can we customize toolbar?

You can customize toolbars in the main window, editors, and dialogs. To display the toolbar, select the Toolbar command on the Options menu. A check mark indicates that the toolbar is active. To modify the toolbar, select Customize Toolbar on the Options menu (or double-click the toolbar area).

How do I add an icon to the android toolbar?

Now if you want to add other resolutions pictures to this drawable, just do it in the same manner. Step 5) And now go to the other folder which is Settings -> Androids-> drawable hdpi. And then go to your Android, then drawable, paste it here and inside this drawable-hdpi and click Ok.


1 Answers

Try adding this to your ImageView:

android:layout_gravity="end" 
like image 58
Sam Avatar answered Oct 22 '22 06:10

Sam