Android v7 Toolbar button alignment
You should add android:layout_gravity="end"
for your Button :
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:id="@+id/showevents" android:textSize="12sp" android:background="@null" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:textColor="#FFF" android:text="UPCOMING \nEVENTS"/>
Or for image on the top right:
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:minHeight="?attr/actionBarSize" android:background="@color/colorPrimary" android:layout_width="match_parent" android:layout_height="wrap_content" app:title="Edit Note"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:id="@+id/submitEditNote" android:src="@android:drawable/ic_menu_send" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" /></android.support.v7.widget.Toolbar>
I hope it helps
Your way is right but take a look at official doc: (Resourcs)
Create menu of items:
<!-- "Mark Favorite", should appear as action button if possible --><item android:id="@+id/action_favorite" android:icon="@drawable/ic_favorite_black_48dp" android:title="@string/action_favorite" app:showAsAction="ifRoom"/><!-- Settings, should always be in the overflow --><item android:id="@+id/action_settings" android:title="@string/action_settings" app:showAsAction="never"/>
Add menu action by ID
@Overridepublic boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_settings: // User chose the "Settings" item, show the app settings UI... return true; case R.id.action_favorite: // User chose the "Favorite" action, mark the current item // as a favorite... return true; default: // If we got here, the user's action was not recognized. // Invoke the superclass to handle it. return super.onOptionsItemSelected(item); }}