1 / 6

Menu 設定方法

Menu 設定方法. OptionMenu- 直接設定. public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. //getMenuInflater().inflate(R.menu.activity_main, menu); menu.add(1,1,0," 多媒體播放 "); menu.add(1,2,1," 定位系統 "); menu.add(1,3,2," 影片播放 ");

Download Presentation

Menu 設定方法

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Menu 設定方法

  2. OptionMenu-直接設定 • public boolean onCreateOptionsMenu(Menu menu) { • // Inflate the menu; this adds items to the action bar if it is present. • //getMenuInflater().inflate(R.menu.activity_main, menu); • menu.add(1,1,0,"多媒體播放"); • menu.add(1,2,1,"定位系統"); • menu.add(1,3,2,"影片播放"); • menu.add(1,4,3,"網路瀏覽"); • menu.add(1,5,4,"地圖顯示"); • menu.add(1,6,5,"天氣預報"); • menu.add(1,7,6,"行事錄"); • return true; • }

  3. 點擊啟動 • public boolean onOptionsItemSelected(MenuItem item) { • switch(item.getItemId()) { • case 1: • Show1(); • return true; • case 2: • Show2(); • return true; • case 3:/case 4:/case 5:/case 6: • case 7: • Show3(); • return true; • } • return super.onOptionsItemSelected(item); • }

  4. ContextMenu • public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { • super.onCreateContextMenu(menu, v, menuInfo); • menu.add(1,1,0,”Edit"); • menu.add(1,2,1,“Save"); • } • public boolean onContextItemSelected(MenuItem item) { • switch (item.getItemId()) { • case 1: • Show1(); • return true; • case 2: • Show2(); • return true; • default: • return super.onContextItemSelected(item); • } • }

  5. 註冊 • TextView textView=(TextView)findViewById(R.id.textview1); • registerForContextMenu(textView);

  6. Sub Menu • public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { • super.onCreateContextMenu(menu, v, menuInfo); • SubMenu editMenu=menu.addSubMenu(1,1,0,"編輯"); • SubMenu checkMenu=menu.addSubMenu(1,2,0,"檢查"); • editMenu.add(1,3,0,"編輯檔案"); • editMenu.add(1,4,1,"編輯資料表"); • checkMenu.add(1,5,0,"檢查有效日期"); • checkMenu.add(1,6,1,"檢查授權"); • checkMenu.add(1,7,2,"檢查預算"); • }

More Related