shine_joseph shine_joseph - 16 days ago 7
Android Question

set icon at the end of toolbar

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.

Sam Sam
Answer

Try adding this to your ImageView:

android:layout_gravity="end"