doesn't show action bar items - android - android

I don't know what to do with this problem. I changed it a lot but it still don't show sherlock action bar items.
here is my code:
public boolean onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu);
MenuInflater minflater = this.getSupportMenuInflater();
minflater.inflate(R.menu.activity_main, (com.actionbarsherlock.view.Menu) menu);
return super.onCreateOptionsMenu(menu);
}
I use Sherlock Activity.
if any one can help me please notice me.
Thanks

#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater minflater = getSupportMenuInflater();
minflater.inflate(R.menu.activity_main, menu);
return true;
}
And make sure you have these imports:
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
You should try and avoid these: minflater.inflate(R.menu.activity_main, (com.actionbarsherlock.view.Menu) menu);
And declare your activity_main.xml like this (pseudo code):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menuStatusUpdate"
android:icon="#drawable/ic_action_status"
android:showAsAction="ifRoom|withText"
android:title="Status Update">
</item>
<item
android:id="#+id/menuPhotoUpload"
android:icon="#drawable/ic_action_gallery"
android:showAsAction="ifRoom|withText"
android:title="Photo">
</item>
</menu>
You can play with this attribute: android:showAsAction="ifRoom|withText" and replace the ifRoom|withText with always

Related

Can't inflate the menu

I am going to inflate a menu in my first Activity.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
The R.menu.main:
<item
android:id="#+id/action_serach"
android:title="Search"
android:orderInCategory="100"
android:icon="#drawable/ic_search"
app:showAsAction="ifRoom" />
It doesn't work, but it inflates the another XML file named R.menu.menu_home.
The R.menu.menu_home:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_star"
android:title="Search"
android:orderInCategory="100"
android:icon="#drawable/ic_star_half"
app:showAsAction="ifRoom"
/>
</menu>
But in my second Activity, it works, whether it's R.menu.main or R.menu.menu_home.
why?
I think the problem is that you have to Override the class method, so add #Override before.
Here you can get more info about the Override annotation.
I have solve this problem.It's because i replace the framelayout with a fragment in the activity and the onCreateOptionsMenu() method is in the fragment.
Use this code.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}

Submenu in actionbar not working after supportInvalidateOptionsMenu is called

I have an activity that extends the ActionBarActivity that's included in the support package revision 18. I have a menu item that contains a submenu and it works fine when I load up the app. However, if I call supportInvalidateOptionsMenu() for some reason the submenu doesn't pop up any more. The related code would be the xml for the menu
<?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/menu_search"
android:icon="#drawable/ic_search"
android:title="#string/menu_search"
myapp:actionViewClass="android.support.v7.widget.SearchView"
myapp:showAsAction="always|collapseActionView"/>
<item
android:id="#+id/menu_now_playing"
android:icon="#drawable/ic_nowplaying"
android:title="#string/menu_nowplaying"
myapp:showAsAction="always"/>
<item
android:id="#+id/menu_station_overflow"
android:icon="#drawable/ic_overflow"
android:title="#string/more"
myapp:showAsAction="always">
<menu>
<item
android:id="#+id/menu_favorite"
android:icon="#drawable/ic_favorite"
android:title="#string/favorite"/>
</menu>
</item>
</menu>
And then the code to create the menu
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity, menu);
return super.onCreateOptionsMenu(menu);
}
I should note that this problem occurs on Gingerbread devices but there are no problems on android 4.x. Does anyone have any idea what might be going on here?
Here is a work-around (as we had the same issue). Any menu items that need to be modified later, we put into instance variables, example:
private MenuItem stationMenuItem;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity, menu);
stationMenuItem = menu.findItem(R.id.menu_station_overflow);
return super.onCreateOptionsMenu(menu);
}
public void doStuff(boolean menuVisible) {
if (stationMenuItem != null) {
stationMenuItem.setVisible(menuVisible);
}
}
This is NOT an ideal solution, but something that will work till this is fixed. Changes to menu items SHOULD happen in onPrepareOptionsMenu(Menu menu) after calling supportInvalidateOptionsMenu()
Do not return super.onCreateOptionsMenu(menu); because that will always return false. Just return true.

I want to add buttons next to the option button in Tablets

I want to add some buttons next to the system option menu , how can I do that?
try
action bar
Icon of Action bar
#Override
public boolean onCreateOptionsMenu(Menu menu) {
android.view.MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
Menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/save_button"
android:title="i"
android:showAsAction="always" />
</menu>

Option Menu does not appear in Android

I have this code to create the menu:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.tip_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MNU_PREV:
animateTextViewsPrev();
break;
case MNU_NEXT:
animateTextViewsNext();
break;
}
return true;
}
And the XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/prev_tip" android:title="#string/prevTip"></item>
<item android:id="#+id/next_tip" android:title="#string/nextTip"></item>
</menu>
In a smartphone with Android 2.1 the menu is visible but in other mobile whit 4.1.1 is invisible.
Somebody now how to solve it?
What is you target Android, good to know, in android 4.0 them has redesign the menu layout.
I think you is missing super.onCreateOptionsMenu(menu); in the call onCreateOptionsMenu
In my code I has,
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
I was dealing with the same problem.. read some queries and documentation.. Hope this might help you.
Here's my XML file for a menu..
<item
android:id="#+id/action_send_feedback"
android:orderInCategory="100"
android:showAsAction="always"
android:title="#string/action_send_feedback"/>
<item
android:id="#+id/action_share_app"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="#string/action_share_app"
android:icon="#drawable/ic_action_share" />
<item
android:id="#+id/action_rate_app"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/action_rate_app"/>
JAVA Code goes here..
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
For android phones which have option button (at the bottom of the phone) the menu item which are showAsAction="never" comes when the button is pressed.. or else they will be shown normally on the action bar options menu..
Ref: http://developer.android.com/guide/topics/ui/menus.html#options-menu
You can simply change the "targetSdkVersion" to 10 in manifest file
It needs the ID in the java! :)

Adding a button to the ActionBar with ActionBarSherlock

I have been trying to add a button to the SherlockActionBar but I can't get it working.
This is the code that I have:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
android.view.MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, (android.view.Menu) menu);
return super.onCreateOptionsMenu(menu);
}
This is my menu.xml code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/save_button"
android:title="i"
android:showAsAction="always" />
</menu>
This doesn't work, as even if I press the menu button, nothing shows up.
Is there any other way? Am I making any mistake?
You are using Android's Menu and MenuInflater, but should be using the classes that come with ActionBarSherlock:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, (com.actionbarsherlock.view.Menu) menu);
return super.onCreateOptionsMenu(menu);
}
It seems like you are intermingling the two right now. Make sure that you import only com.actionbarsherlock.view.Menu and com.actionbarsherlock.view.MenuInflater, and not its Android counterparts. I recommend you to do something like the following:
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
I think in the menu.xml. Your item does not declare android:showAsAction attribute completely.
You must declare it like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/save_button"
android:title="i"
android:showAsAction="always|withText" />
</menu>
Since you did not specify any icon for the item action bar cannot display any item. By default icon are display than text.

Categories

Resources