Issue
My activities extend ActionBarActivity. My problem is that when I run the app on an actual device (Galaxy S2) with Android 4.2, the menu is NOT place in the action bar, but in the bottom of the app. And the physical options button on the device has to be pressed so that it is visible. BUT on AVD powered with Android 4.2 the menu is placed on top right corner of the app on the action bar.
I want my action bar icons to appear all on right side of the action bar on top right corner of the app. NOT as a group in a menu, nor on the bottom.
I have tried different options of showAsAction. Does no good. For example "always" just places a fixed ribbon on the bottom which contains the menu. Not separate items, not on the top!
Thanks a lot for your help in advance.
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.**.**" android:versionCode="3" android:versionName="1.0.2" android:installLocation="auto"> <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
Menu XML
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.**.**.AboutActivity"
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_bar_settings"
app:showAsAction="always"/>
<item android:id="@+id/action_search"
android:icon="@drawable/ic_launcher"
android:title="map"
app:showAsAction="always"/>
<item android:id="@+id/action_compose"
android:icon="@drawable/contact_info"
android:title="test"
app:showAsAction="always"/>
My activity:
public class ActivityAbout extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.container, new FragmentAbout()).commit();
}
int currentAPIVersion = android.os.Build.VERSION.SDK_INT;
if (currentAPIVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.about, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) {
Intent intent=new Intent(ActivityAbout.this, ActivityAbout.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Solution
This is how Android acts on different devices.
If the device has the hardware option key the ActionBar
dosent show the OverflowMenu
(Menu with three dots at the top).
You cant modify how android works, so you cant show the OverflowMneu
on devices with a hardware menu key.
NOT RECOMMENDED
But you can fake this menu by adding a menu item with three dots icon and use PopupMenu
.
UPDATE
You are using the ActionBarCompat lib, you need to change the menu xml to
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_bar_settings"
app:showAsAction="always"/>
</menu>
Plus, you dont need to check the API level, its handled by the compat lib.
Answered By - JafarKhQ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.