andriod开发增加一个菜单

 

第一步:

E:\01.prj\pyscrapy\Cet4\res\menu\main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>

   <item
        android:id="@+id/action_network"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_network"/>

</menu>

 

第二步:

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

第三步:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
        case R.id.action_network:
            final Intent intent = new Intent(this, NetworkSettingActivity.class);
            startActivity(intent);
            break;
        case R.id.action_settings:
            final Intent intent = new Intent(this, SettingsActivity.class);
            startActivity(intent);
            break;
        default:
            Log.e(TAG, "onOptionsItemSelected: invalid menuitem id " + String.valueOf(item.getItemId()));
            break;
        }

        return true;
    }

 

第四步:

创建activity

posted @ 2015-07-11 10:32  aprial  阅读(253)  评论(0编辑  收藏  举报