在我的应用程序菜单图标没有显示,对于我目前文本/字符串正在显示但我需要文本的图标/图像意图。另请尝试使用xml格式菜单调用。
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>
答案 0 :(得分:2)
可能是......你应该删除:AndroidManifest.xml中的android:theme =“@ style / AppTheme”
或编辑:android:theme =“@ android:style / Theme”