Android 컨트롤 메뉴 생 성 방식

효과 그림 보이 기:
这里写图片描述
첫 번 째 생 성 방식
-------

package com.example.androidthismenus;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }
 //             ,            
 @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);
  //  1( id)  2(     id id)  3(       )  4(     )
  menu.add(0, 100, 1, "    ");
  menu.add(0, 200, 2, "    ");
  menu.add(0, 300, 3, "    ");
  menu.add(0, 400, 4, "    ");
  return true;
 }
 //                
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  if (id == R.id.action_settings) {
   return true;
  }
  return super.onOptionsItemSelected(item);
 }
}
두 번 째 생 성 방식:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
 <item
  android:id="@+id/menu_new"
  android:icon="@android:drawable/ic_menu_help"
  android:title="  "/>
 <item
  android:id="@+id/menu_delete"
  android:icon="@android:drawable/ic_menu_delete"
  android:title="  "/>
 <item android:title="   ">
  <menu >
   <item android:id="@+id/menu_sub1"
    android:title="   1"/>
   <item android:id="@+id/menu_sub2"
    android:title="   2"/>
  </menu>
 </item>
</menu>

//         Activyt    menu  
MenuInflater mInflater = getMenuInflater(); mInflater.inflate(R.menu.menu, menu);
컨 텍스트 메뉴:
这里写图片描述
팝 업 메뉴:
这里写图片描述
총결산
위 에서 말 한 것 은 소 편 이 소개 한 안 드 로 이 드 컨트롤 메뉴 의 생 성 방식 입 니 다.여러분 에 게 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 면 메 시 지 를 남 겨 주세요.소 편 은 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기