Legacy menu is not showing in android - android

I am developing an app with actionbarsherlock. Because i need to add compatibility for device under 3.0. In main(first) activity i need to hide actionbar (for design issue). Also that activity has an option menu. Question is how can i add legacy menu for recent version of device which doen't have any hardware menu button. I have checked all the options but not working. I am adding some options here
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.coredialer_menu, menu);
return true;
}
#manifest
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="10" />

I have solved my problem by removing actionbarsherlock.

Related

OptionsMenu doesn`t appear

I have ListFragment and i want manage ActionBar. However, it does not appear on the screen.
Here is code for ListFragment:
#Override
public void onCreate(Bundle saved) {
super.onCreate(saved);
setHasOptionsMenu(true);
...
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.fragment_crime_list, menu);
}
fragment_crime_list:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_item_new_crime"
android:icon="#android:drawable/ic_menu_add"
android:title="#string/new_crime"
android:showAsAction="ifRoom|withText" />
</menu>
In my manifest.xml i have set only minSdkVersion but it doesnt help
<uses-sdk
android:minSdkVersion="8"
/>
Any suggestions?
The action bar is not added by default in your activity and it's also added in API level 11 not 8. So to add it, you have two options that I'll address here
On API level 11 or higher
The action bar is included in all activities that use the Theme.Holo theme (or one of its descendants), which is the default theme when either the targetSdkVersion or minSdkVersion attribute is set to "11" or higher. If you don't want the action bar for an activity, set the activity theme to Theme.Holo.NoActionBar.
API level 7 or higher
You have to use the appcompat v7 library that you can find exactly how to add it here.
For fragments you need to setsetHasOptionsMenu(true); in your oncreatView()
just call super constructor of onCreateOptionMenu it will work
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_sample, menu);
super.onCreateOptionsMenu(menu,inflater);
}

after switching language,fragment will increase duplicate option menu item

in v4.fragment, i set setHasOptionsMenu(true); and then in onCreateOptionsMenu i set inflater.inflate(R.menu.menu_fragment, menu);, everything is ok until i switch language.
when the app is running, and i press home-key, open setting, change locale language, select my running app from recently app list, the option menu in actionbar will increase duplicate menuitem, what's happen?
Gemini, I know it is late and you most probably have the answer already. The easiest way to fix this issue is to just add menu.clear();
public void onPrepareOptionsMenu(Menu menu) {
MenuInflater inflater = new MenuInflater(getActivity().getApplicationContext());
menu.clear();
super.onPrepareOptionsMenu(menu);
inflater.inflate(R.menu.myMenu, menu);
}

Menu button is not show in 3.0 OS

I have created menu button which have two functions bookmark and home button.
This is working well in all the android version without android 3.0
do here any ways ? so my menu button will be display also in android 3.0 with all the version.
my code:-
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.menu_bookmark:
db.updateContact(new Contact(itemN,imageStatus));
return true;
case R.id.home_page:
Intent i = new Intent(imageTouchs.this, Comics.class);
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu, menu);
return true;
}
and my androidmanifest.xml :-
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="15" />
menu.xml :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_bookmark"
android:title="Bookmark"
android:showAsAction="ifRoom|withText" />
<item android:id="#+id/home_page"
android:title="Home"
android:showAsAction="ifRoom|withText" />
</menu>
any menu is not display in action bar
The "overflow' button will only show up when there isn't a physical menu button on the device. This is the standard behavior for the ActionBar.
You can actually set the value of your AVD to specifically not have a menu button when you are configuring the image.
Here is a SO question addressing this same thing: Action bar overflow not displayed
If you are talking about the OverFlowMenu icon, to the best of my knowledge, it cannot be achieved (forced) using the standard Android Support Library.
If you must have an OverFlowMenu (forced), you will need to use the ActionBarSherlock library. Go through a couple of my answers where I have a few fairly detailed suggestions on how to achieve that:
https://stackoverflow.com/a/13307583/450534
https://stackoverflow.com/a/13180285/450534
NOTE: As already mentioned in both my answers linked above, this is not recommended to ensure users get a seamless UI on their devices. And also, if you must absolutely force the OverFlowMenu, you will need to use an older version of ABS, which is again, not recommended.

Android Jellybean onCreateOptionsMenu is not called on Nexus 7

I have a TabActivity with four tabs. When I set android:targetSdkVersion="15" the onCreateOptionsMenu method is not called on any of the tab activities when testing on a Nexus 7.
It works correctly with android:targetSdkVersion="10".
With android:targetSdkVersion="15" it works correctly when the activities are not in a TabActivity and when tested on a phone (Evo).
Here is the code for onCreateOptionsMenu.
public boolean onCreateOptionsMenu(Menu menu) {
Log.i("Test","Base In create option menu");
if( menuId != null ) {
new MenuInflater(this).inflate(menuId,menu);
}
return super.onCreateOptionsMenu(menu);
}
Sorry but this is an easy one. According to Google:
http://developer.android.com/guide/topics/ui/menus.html
So, if you set the target SDK lower, you can show the deprecated options bar. For the newer SDKs you need to use an action bar or some other form of navigation. Basically Google decided that not all devices would have a "menu" button.

onCreateOptionsMenu not being called on FragmentActivity when run on phone version

I create an app that supports both phone and tablet version so i use the android-support-v4.jar library. My activity extends the FragmentActivity and override the onCreateOptionsMenu(Menu menu). This works fine on tablet, the onCreateOptionsMenu being called correctly but it doesn't work on phone, onCreateOptionsMenu never get called. How to resolve this?
Note: i use <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="12"/> on Manifest file.
You should consider from your Fragment code:
1) Implementing onCreateOptionsMenu(Menu menu, MenuInflater inflater)
2) Calling setHasOptionsMenu
3) And also implementing onOptionsItemSelected(MenuItem item)
Then you will be ok on both the phone and tablet.

Categories

Resources