无法在Android 4.2.2选项菜单中设置图标

时间:2013-10-06 15:04:38

标签: android menu oncreateoptionsmenu

我想知道为什么我无法在选项菜单中添加图标。我正在开发Android 4.2中的应用程序,我想添加自定义菜单选项。我在做如下:  在菜单文件夹中 - > home_activity.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/about_us"
    android:title="@string/HomeActivity_aboutUs_item"
    android:orderInCategory="100"
    android:icon="@drawable/apply_img"

/>
<item
    android:id="@+id/help"
    android:title="@string/HomeActivity_help_item"
    android:icon="@drawable/browsefile"
    android:orderInCategory="102"

/>

在home_activity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.home_activity, menu);
    return true;
}

    @Override
public boolean onOptionsItemSelected(MenuItem item) {
    Resources resources = getResources();
    switch(item.getItemId()) {
        case R.id.about_us:


            return true;
        case R.id.help:

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

在home_activity.xml

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".HomeActivity" >
<TextView
    android:id="@+id/HomeActivity_TextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="50dp"
    android:text="@string/HomeActivity_TextView_text"
    android:textStyle="bold"
    android:textSize="18sp" /> </RelativeLayout>

0 个答案:

没有答案