0

我想知道为什么我无法在选项菜单中添加图标。我正在 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>
4

0 回答 0