why cant i see my option menu - android

I write an option menu code with a tutorial.
and for some reason it didnt work.
my checker_page_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:MyApp="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/waiters_filtering"
android:title="#string/waiters"
MyApp:showAsAction="always"
/>
<item android:id="#+id/areas_filtering"
android:title="#string/waiters"
MyApp:showAsAction="always"
/>
<item android:id="#+id/tables_filtering"
android:title="#string/waiters"
MyApp:showAsAction="always"
/>
<item android:id="#+id/tapas_filtering"
android:title="#string/waiters"
MyApp:showAsAction="always"
/>
</menu>
and my totaly normal OnCreatOptinMenu in the MainActivity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.checker_page_menu, menu);
return true;
}
What seems to be the problem and why cant i see my optionMenu?

Related

Why is the menu item not showing as an action?

this is the xml file :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/main_main_prefs"
android:icon="#drawable/ic_tune_white_24px"
android:title="#string/menu_settings"
android:visible="true"
app:showAsAction="always" />
</menu>
But this is the case in actual device:
Update: this is the menu inflation code. And the picture is the response in real device.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
(new MenuInflater(this)).inflate(R.menu.menu_main,menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.main_main_prefs:
Toasty.info(this,"Prefs Was Clicked").show();
break;
}
return super.onOptionsItemSelected(item);
}
You have to create menu like this
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
instead of
(new MenuInflater(this)).inflate(R.menu.main,menu);
return super.onCreateOptionsMenu(menu);
You can try adding android:orderInCategory. Something like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/main_main_prefs"
android:icon="#drawable/ic_tune_white_24px"
android:title="#string/menu_settings"
android:orderInCategory="100"
android:visible="true"
app:showAsAction="always" />
</menu>

Android Action Bar Menu Item Title

Why does not show the action_call.title in the second device ??
I want to show the action_call.title on each device.
this device Android 5.1.1 (api22) 7"
this device Android 6.0 (api23) 5.96"
this is my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_call"
android:icon="#drawable/call"
android:title="#string/action_call"
android:visible="true"
app:showAsAction="ifRoom|withText" />
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
<item
android:id="#+id/action_info"
android:icon="#drawable/info2"
android:title="#string/action_info"
app:showAsAction="never|withText" />
</menu>
this is my onCreateOptionsMenu on MainActivity.java
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem action_call = menu.findItem(R.id.action_call);
action_call.setTitle("+99");
return true;
}

How to show menu item in action bar?

I want the menu items to show on action bar. There is a lot of space on the ActionBar, but still they don't show up. Every item shown as three dots, why?
.java file
public class GalleryActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_layout);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
}
.xml file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:MissionAndroid="http://schemas.android.com/tools">
<item
android:id="#+id/facebookId"
android:title="facebook"
android:icon="#drawable/facebook"
MissionAndroid:showAsAction="always"/>
<item
android:id="#+id/shareId"
android:title="share"
android:icon="#drawable/share"
MissionAndroid:showAsAction="always"/>
<item
android:id="#+id/delete"
android:title="delete"
android:icon="#drawable/delete"
MissionAndroid:showAsAction="always"/>
<item
android:id="#+id/searchId"
android:title="search"
android:icon="#drawable/search"
MissionAndroid:showAsAction="ifRoom"/>
</menu>
Currently, you're using "http://schemas.android.com/tools" which does not offer the functionality you're looking for and your showAsAction modifiers are being ignored.
Try updating your main_menu.xml with the following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:MissionAndroid="http://schemas.android.com/apk/res-auto">
...
</menu>
Better yet, to follow convention, replace MissionAndroid in this file with app:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/facebookId"
android:title="facebook"
android:icon="#drawable/facebook"
app:showAsAction="always"/>
...
</menu>

android option menu with icon

How to show icon with option menu.I have tried the following code but my option menu is without image icon.I am using android version 4.0 for developing app.
Java code :
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add("Add Contacts").setIcon(
R.drawable.ic_launcher);
return true;
}
Following is my app's screen shot
I need image to be displayed on the top of "Add Contacts" item.
Override OnPrepareOptionsMenu and add icon from there too
and if its for above 3.0, use android:showAsAction in xml.
eg. android:showAsAction="ifRoom|withText"
I tried the code in two line and it works:
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add("Add Contacts");
menu.getItem(0).setIcon(R.drawable.ic_launcher);
return true;
}
You can create a custom menu like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/add_contacts"
android:icon="#drawable/ic_launcher"
android:title="#string/add_contacts"
/>
</menu>
And then inflate it
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
return true;
}
More on this here:
http://developer.android.com/guide/topics/ui/menus.html#options-menu
you can directly set this into the xml file.
<item android:id="#+id/add_contacts"
android:icon="#android:drawable/plus_icon"
android:title="Add Contacts"/>
You Can try Following this Link.
Check this out and tell me if it worked or not.
Or you can do some thing like this.
Create menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/next"
android:icon="#drawable/ic_next"
android:title="#string/next" />
<item android:id="#+id/previous"
android:icon="#drawable/ic_previous"
android:title="#string/previous" />
<item android:id="#+id/list"
android:icon="#drawable/ic_list"
android:title="#string/list" />
</menu>
And now you will be able to set ICON on menu
Now in CreateOptionMenu
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
And to access that menu.
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.next:
Toast.makeText(this, "You have chosen the " + getResources().getString(R.string.next) + " menu option",
Toast.LENGTH_SHORT).show();
return true;
…
default:
return super.onOptionsItemSelected(item);
}
}
To enable Option Menu with Icons:
Wrap the Items with an Item with showAsAction="always" and a Menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="#string/title_menu"
android:icon="#mipmap/ic_icon_menu"
app:showAsAction="always">
<menu>
<item
android:id="#+id/action1"
android:orderInCategory="100"
android:title="#string/action1"
android:icon="#mipmap/ic_icon_action1"
app:showAsAction="never" />
</menu>
</item>
</menu>
If you use some following attribute in manifest file then it's will be show your icon....
<activity android:name=".ui.CategoryActivity"
android:label="#string/app_name"
**android:theme="#android:style/Theme.NoTitleBar"**></activity>
It's work fine for me...:)
+1 for my own effort...
**must be enter.
Easiest way is to use the #drawable only when setting your menu item.
OR
Simply put the #drawable before the title declaration.
<?xml version="1.0" encoding="UTF-8" ?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app ="http://schemas.android.com/apk/res-auto">
<item
android:id ="#+id/addToFavorites"
android:icon = "#drawable/ic_favorite_border_white_24dp"
android:title = "Hello"
app:showAsAction="always" />
<item
android:id ="#+id/about"
android:title ="About"
app:showAsAction="never" />
</menu>
the problem is the Androidmanifest.xml.
Remove android:theme="#style/AppTheme" and it will work just fine

OptionMenu does not show anything

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// mEditor=(TextView)findViewById(R.id.text);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
Log.d("sayem", "onCreateOptionMEnu");
return true;
}
And this is my menu.xml file path res/menu/menu.xml
<item
android:id="#+id/settings"
android:alphabeticShortcut="#string/settings_shortcut"
android:icon="#drawable/violet"
android:title="#string/settings_label"
android:visible="true"/>
It does not show any kind of menu as expected.
If you look at the example here, the menu.xml file (or game_menu.xml file) has an outer tag called <menu>. I don't see that in yours.
Example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/new_game"
android:icon="#drawable/ic_new_game"
android:title="#string/new_game" />
<item android:id="#+id/help"
android:icon="#drawable/ic_help"
android:title="#string/help" />
</menu>
Either you have not posted your full menu.xml, or it isn't formed as it should be.

Categories

Resources