我正在开发一个带有 Action Bar Sherlock 库的 android 应用程序,它在我的设备上使用 api 17“图像 1”正常运行,但在 api 8 上,我在操作栏上的旧菜单样式“图像 2” ",按照我的菜单代码:
菜单 XML 文件:
<item
android:id="@+id/menu_main_filter"
android:alphabeticShortcut="@string/action_filter_shortcurt"
android:icon="@drawable/ic_action_filter"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="@string/action_filter"/>
<item
android:id="@+id/menu_main_share"
android:alphabeticShortcut="@string/action_share_shortcurt"
android:icon="@drawable/ic_action_share"
android:orderInCategory="101"
android:showAsAction="ifRoom"
android:title="@string/action_share"/>
<item
android:id="@+id/menu_main_about"
android:alphabeticShortcut="@string/action_about_shortcurt"
android:icon="@drawable/ic_action_about"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="@string/action_about"/>
<group
android:id="@+id/menu_main_group_display_settings"
android:checkableBehavior="single"
android:orderInCategory="1000" >
<item
android:id="@+id/menu_main_use_indian_numbers"
android:alphabeticShortcut="@string/action_use_indian_numbers_shortcurt"
android:icon="@drawable/ic_action_indian"
android:orderInCategory="10001"
android:showAsAction="ifRoom"
android:title="@string/action_use_indian_numbers"
android:titleCondensed="@string/action_use_indian_numbers_condensed"/>
<item
android:id="@+id/menu_main_use_arabic_numbers"
android:alphabeticShortcut="@string/action_use_arabic_numbers_shortcurt"
android:icon="@drawable/ic_action_arabic"
android:orderInCategory="10002"
android:showAsAction="ifRoom"
android:title="@string/action_use_arabic_numbers"
android:titleCondensed="@string/action_use_arabic_numbers_condensed"/>
</group>
活动java代码:
public class MainActivity extends AbstractNombrojActivity {
private ListView listView;
private ListMainAdapter<Nombro> listMainAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.main_listview);
listMainAdapter = new ListMainAdapter<Nombro>(getApplicationContext());
listView.setAdapter(listMainAdapter);
listView.setEmptyView(findViewById(R.id.main_listview_emptyview));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
NombrojPreferences preferences = new NombrojPreferences(getApplicationContext());
for (int c = 0; c < menu.size(); c++) {
MenuItem menuItem = menu.getItem(c);
if (menuItem.getItemId() == R.id.menu_main_use_indian_numbers && preferences.getNumberAlgarism() == NumbersAlgarism.Indian)
menuItem.setChecked(true);
if (menuItem.getItemId() == R.id.menu_main_use_arabic_numbers && preferences.getNumberAlgarism() == NumbersAlgarism.Arabic)
menuItem.setChecked(true);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_main_use_indian_numbers:
new NombrojPreferences(getApplicationContext()).setNumberAlgarism(NumbersAlgarism.Indian);
invalidate();
return true;
case R.id.menu_main_use_arabic_numbers:
new NombrojPreferences(getApplicationContext()).setNumberAlgarism(NumbersAlgarism.Arabic);
invalidate();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
// custom
private void invalidate() {
supportInvalidateOptionsMenu();
listMainAdapter.notifyDataSetChanged();
}
我的应用主题:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
关于价值观:
<style name="AppBaseTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar"></style>
<style name="AppTheme" parent="AppBaseTheme"></style>
关于值-v11:
<style name="AppBaseTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar"></style>
和价值观-v14:
<style name="AppBaseTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar"></style>
什么会导致这种错误行为?
图片1:
图 2:
非常感谢!