我想设置我的子菜单(如this),但它不起作用。
我尝试使用("Android Action Bar Style Generator")这样做,这种方式也不适用于我。
这是我的代码......
爪哇:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.meal, menu);
MenuItem menuItem = menu.findItem(R.id.itemList);
for(Item item : o.getItems()){
menuItem.getSubMenu().add(item.getName());
}
return true;
}
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="apppackage" >
<item android:id="@+id/catList"
android:title="CatList"
android:icon="@drawable/ic_menu_moreoverflow"
app:showAsAction="always">
<menu></menu>
</item>
</menu>
另外我试过这个......但它不起作用。
<style name="AppTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionDropDownStyle">@style/MyDropDownNav</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/blue</item>
<!-- Support library compatibility -->
<item name="background">@color/blue</item>
<item name="android:spinnerDropDownItemStyle">@style/MyWidget.DropDownItem.Spinner</item>
</style>
<style name="MyDropDownNav" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="background">@color/blue</item>
<item name="android:background">@color/blue</item>
<item name="android:popupBackground">@color/blue</item>
<item name="android:dropDownSelector">@color/blue</item>
</style>
<style name="MyWidget.DropDownItem.Spinner" parent="Widget.AppCompat.DropDownItem.Spinner">
<item name="android:textColor">@color/white</item>
</style>
感谢您的帮助!
答案 0 :(得分:0)
试试这个:
<style name="AppTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionDropDownStyle">@style/MyDropDownNav</item>
<item name="android:actionBarWidgetTheme">@style/PopupWrapper</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/blue</item>
<!-- Support library compatibility -->
<item name="background">@color/blue</item>
<item name="android:spinnerDropDownItemStyle">@style/MyWidget.DropDownItem.Spinner</item>
</style>
<style name="MyDropDownNav" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="background">@color/blue</item>
<item name="android:background">@color/blue</item>
<item name="android:popupBackground">@color/blue</item>
<item name="android:dropDownSelector">@color/blue</item>
</style>
<style name="MyWidget.DropDownItem.Spinner" parent="Widget.AppCompat.DropDownItem.Spinner">
<item name="android:textColor">@color/white</item>
</style>
<style name="PopupWrapper" parent="@android:style/Theme.Holo">
<item name="android:popupMenuStyle">@style/MyDropDownNav</item>
</style>