Does anyone have an idea about how to customize the options menu item?. so I need to change display text below icon of the option menu item in a toolbar.
Asked
Active
Viewed 562 times
-2
-
2Possible duplicate of [Custom view for Menu Item](https://stackoverflow.com/questions/26259162/custom-view-for-menu-item) – ADM Nov 30 '18 at 05:33
-
@ADM I want to display text below icon?. – Damini Mehra Nov 30 '18 at 05:36
-
Yeah you can do that by using a custom view . – ADM Nov 30 '18 at 05:43
2 Answers
0
Use Custom toolbar :-
<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="?attr/actionBarSize"
android:background="@color/colorWhite"
android:elevation="0dp"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/back_imageView"
android:layout_width="@dimen/card_h"
android:layout_height="@dimen/card_h"
android:layout_centerVertical="true"
android:contentDescription="@string/app_name"
android:paddingBottom="@dimen/small_margin"
android:paddingRight="@dimen/med_margin"
android:paddingTop="@dimen/small_margin"
android:src="@mipmap/back" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<ImageView
android:id="@+id/right_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/iv_dob"
android:layout_gravity="center"
android:contentDescription="@string/app_name" />
<TextView
android:id="@+id/first_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/lato_bold"
android:text="@string/app_name"
android:textAllCaps="true"
android:textColor="@color/colortext"
android:textSize="@dimen/normal_text_size" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>

Anita
- 39
- 1
- 7
0
You can use custom action Layout and put into menu Item:
Here is XML for menu.
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Eventapp="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_create"
android:actionLayout="@layout/action_view_details_layout"
android:orderInCategory="50"
android:showAsAction = "always"/>
</menu>
The Layout is
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/create"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:src="@drawable/icon"/>
</LinearLayout>
this will show the icon and the text in vertical fashion.

Chetan Joshi
- 5,582
- 4
- 30
- 43
-
this is a good idea but I have lots of items in an options menu.so I need to make lots of layout for all the menu items. – Damini Mehra Nov 30 '18 at 06:25
-
no you can use single layout for menu item and use it at all places . – Chetan Joshi Nov 30 '18 at 06:27
-
-
If yo want to display more than 4 items you should consider **bottomsheet** or **Popupdialog** to display those options to user. this will look good and will give you more control for design and event handling. – Wasim K. Memon Nov 30 '18 at 06:36