在我的应用程序菜单图标未显示,对我来说目前正在显示文本/字符串,但我需要文本的图标/图像意图。也尝试使用 xml 格式的菜单调用。
- 安卓版本是ver_4
- 科尔多瓦_2.5.0
- 图片/图标大小=32*32
testapp.java
package com.example.testapp;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import org.apache.cordova.*;
import android.view.Menu;
import android.view.MenuItem;
public class testapp extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
private static final int HOME = 0;
private static final int SETTINGS = 1;
private static final int HELP = 2;
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, HOME, 0, "Home")
.setIcon(R.drawable.icon_home)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0, SETTINGS, 0, "Settings")
.setIcon(R.drawable.icon_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0, HELP, 0, "Help")
.setIcon(R.drawable.icon_help)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case HOME:
// app icon in action bar clicked; go home
Intent intent = new Intent(this, testapp.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
case SETTINGS:
this.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
return true;
case HELP:
this.appView.sendJavascript("navigator.notification.alert('No help')");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
我的 testapp.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_home"
android:icon="@drawable/icon_home"
android:showAsAction="ifRoom|withText"
android:title="Home" />
<item android:id="@+id/menu_settings"
android:icon="@drawable/icon_settings"
android:showAsAction="ifRoom|withText"
android:title="Settings" />
<item android:id="@+id/menu_help"
android:icon="@drawable/icon_help"
android:title="Help" />
</menu>