java - Android - Add custom layout to popup menu item -


i've been working @ while. i'm trying create popupmenu top item looks different rest of items - header item contains title.

i've tried setting android:actionlayout item, linking particular item xml file should generate desired layout. however, seems have absolutely no effect. there tried set actionview programmatically - creating custom view , setting item. still no effect.

i've done research here on , looked @ least 10 tutorials; maybe suck @ googling today, cannot find way this.

here last attempt:

// * my_menu.xml <menu     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto">     <group          android:id="@+id/menu_title_group" >         <item              android:id="@+id/menu_title_item"             android:title=""             app:actionlayout="@layout/popup_menu_title_header_layout" />     </group> </menu> 

and then...

// * popup_menu_title_header_layout.xml <?xml version="1.0" encoding="utf-8"?> <textview     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@+id/popup_menu_title_header_text_view"     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:layout_marginstart="8dp"     android:layout_marginleft="8dp"     android:layout_marginend="8dp"     android:layout_marginright="8dp"     android:gravity="center"     android:background="@color/red"     android:textcolor="@color/gray"     android:textsize="16sp"/> 

and then...

    // * showpopupmenu.activity     popupmenu popup = new popupmenu(getactivity(), showmenubutton);     popup.getmenuinflater().inflate(r.menu.my_menu, popup.getmenu());     popup.getmenu().finditem(r.id.menu_title_item).settitle(some_dynamic_string);     popup.getmenu().add(1,0,0,"some_dynamic_option_title_1");     popup.getmenu().add(1,1,0,"some_dynamic_option_title_2"); 

... popup menu appears expected, top item not effected @ actionlayout. note tried using app:actionlayout, suggested some. note, not want use context menu this.

thanks in advance!

use same context of actionbar create popupmenu

actionbar.getthemedcontext() 

so,

actionbar actionbar = ((actionbaractivity)     getactivity()).getsupportactionbar();   popupmenu popmenu = new popupmenu(actionbar.getthemedcontext(), anyview); 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -