I'm using ActionBar Compat in my app and i need to show dropdown menu when user click button in actionbar. In 4.x versions it's ok, but in 2.3 i have something like dialog.
2.3 screenshot
Like i said, in 4.x it's ok:
Here is some code:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.categories, menu);
return super.onCreateOptionsMenu(menu);
}
categories.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:onekr="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/refresh"
android:icon="@drawable/ic_action_refresh"
onekr:showAsAction="always"
android:title="@string/refresh"
android:visible="true">
</item>
<item
android:id="@+id/dissmiss_page_loading"
android:icon="@drawable/ic_action_cancel"
onekr:showAsAction="always"
android:title="@string/cancel"
android:visible="false">
</item>
<item
android:id="@+id/categories"
android:icon="@drawable/ic_action_overflow"
onekr:showAsAction="always"
android:title="@string/categories"
android:visible="true">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:onekr="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/city"
onekr:showAsAction="always"
android:title="@string/city"
android:visible="true">
</item>
<item
android:id="@+id/culture"
onekr:showAsAction="always"
android:title="@string/culture"
android:visible="true">
</item>
</menu>
</item>
</menu>
Why does this can be? How this can be fixed? Big thanks to all who respond!
You may want to use Sherlock Action Bar if your target devices are android SDK < 11.
Have a look at http://actionbarsherlock.com/
Github sample is here: https://github.com/JakeWharton/ActionBarSherlock-Gradle-Sample There is a example here: http://www.androidbegin.com/tutorial/implementing-actionbarsherlock-in-android/ Another example here: http://www.grokkingandroid.com/adding-actionbarsherlock-to-your-project/
If you do not want to use ActionBarSherlock, you have to use android support library, but I would recommend to use ActionBarSherlock
To avoid this, we need use PopupMenu!
For example:
action_bar_buttons.xml
drop_down_menu.xml
in MainActivity.java