Android menu item name not showing

I played android, and I followed the sample menu and it works almost perfectly, but the "title" field of the menu items is not displayed.

I think this is related to this question: https://stackoverflow.com/questions/3286093/android-menu-item-not-showing-text but I'm not sure what his answer means.

In any case, it correctly gets that I have 2 menu items, it just does not display the text. I'm not quite sure where the error is, and I thought that extra sets of eyes would be good.

XML:

<?xml version="1.0" encoding="UTF-8"?> <menu xmlns:android="https://schemas.android.com/apk/res/android"> <item android:id="@+id/options" android:title="@string/main_options" /> <item android:id="@+id/options2" android:title="@string/main_options2" /> </menu> 

Inflatable:

 @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); return true; } 

If anything else is needed let me know.

edit: line file:

 <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World!</string> <string name="app_name">LifeInColor</string> <string name="main_options">Options</string> <string name="main_options2">Something goes here</string> </resources> 

change xml to:

  <?xml version="1.0" encoding="UTF-8"?> <menu xmlns:android="https://schemas.android.com/apk/res/android"> <item android:id="@+id/options" android:title="@string/main_options" /> <item android:id="@+id/options2" android:title="Something goes here" /> </menu> 

gets the same result. I have a photo, but it will not allow me to publish it, because I'm a beginner.

+6
android title menu
source share
4 answers

In your menu file, replace https://schemas.android.com/apk/res/android with http://schemas.android.com/apk/res/android ( httpshttp ). Thus, it seems that the error is caused by an invalid schema address.

+1
source share

The icon may be too large. If you use an icon larger than 48x48 on the hdpi screen, the user will either not see the title or not see the truncated title.

See http://developer.android.com/guide/practices/ui_guidelines/icon_design_menu.html#size9

+1
source share

I needed to specify an icon with android:icon="@null" for each element, after which the title was shown. This works when using the toolbar.

+1
source share

Directly we can add menu items like this, it works great for me

  @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub super.onCreateOptionsMenu(menu); MenuItem item1=menu.add(0, 4, 0,"text1"); item1.setIcon(R.drawable.car); MenuItem item2=menu.add(0, 0, 0, "text2"); item2.setIcon(R.drawable.share); MenuItem item3=menu.add(0, 2, 0, "text3"); item3.setIcon(R.drawable.history); MenuItem item4=menu.add(0, 3, 0, "text4"); item4.setIcon(R.drawable.settings); return true; } 
0
source share

All Articles