0

在我的代码中有一个菜单,我在其中使用图标。但在运行时只出现图标标题而不出现图标。请帮我解决这个问题。在我的代码中有一个菜单,我在其中使用图标。但在运行时只出现图标标题而不出现图标。请帮我解决这个问题

菜单.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Single menu item 
         Set id, icon and Title for each menu item
    -->
    <item android:id="@+id/menu_bookmark"
          android:icon="@drawable/menu_icon"
          android:title="Bookmark" />

    <item android:id="@+id/menu_save"
          android:icon="@drawable/menu_icon1"
          android:title="Save" />

    <item android:id="@+id/menu_search"
          android:icon="@drawable/menu_icon2"
          android:title="Search" />

    <item android:id="@+id/menu_share"
          android:icon="@drawable/menu_icon3"
          android:title="Share" />

    <item android:id="@+id/menu_delete"
          android:icon="@drawable/menu_icon4"
          android:title="Delete" />  

    <item android:id="@+id/menu_preferences"
          android:icon="@drawable/menu_icon5"
          android:title="Preferences" /> 
</menu>

AndroidMenusActivity.java

package example.menuexmp;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class AndroidMenusActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    // Initiating Menu XML file (menu.xml)
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.layout.menu, menu);
        return true;
    }

    /**
     * Event Handling for Individual menu item selected
     * Identify single menu item by it's id
     * */
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {

        switch (item.getItemId())
        {
        case R.id.menu_bookmark:
            // Single menu item is selected do something
            // Ex: launching new activity/screen or show alert message
            Toast.makeText(AndroidMenusActivity.this, "Bookmark is Selected", Toast.LENGTH_SHORT).show();
            return true;

        case R.id.menu_save:
            Toast.makeText(AndroidMenusActivity.this, "Save is Selected", Toast.LENGTH_SHORT).show();
            return true;

        case R.id.menu_search:
            Toast.makeText(AndroidMenusActivity.this, "Search is Selected", Toast.LENGTH_SHORT).show();
            return true;

        case R.id.menu_share:
            Toast.makeText(AndroidMenusActivity.this, "Share is Selected", Toast.LENGTH_SHORT).show();
            return true;

        case R.id.menu_delete:
            Toast.makeText(AndroidMenusActivity.this, "Delete is Selected", Toast.LENGTH_SHORT).show();
            return true;

        case R.id.menu_preferences:
            Toast.makeText(AndroidMenusActivity.this, "Preferences is Selected", Toast.LENGTH_SHORT).show();
            return true;

        default:
            return super.onOptionsItemSelected(item);
        }
    }    

}
4

1 回答 1

0

Hiii 检查此链接..

并告诉我们您正在测试哪个版本。您应该根据要求检查您的 API 版本和代码, 这里

这里

于 2013-09-06T10:57:45.257 回答