欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

android菜單,Android菜單組件

Android中怎么實(shí)現(xiàn)底部菜單欄

一共兩種實(shí)現(xiàn)方式:

創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、右玉網(wǎng)絡(luò)推廣、成都小程序開發(fā)、右玉網(wǎng)絡(luò)營銷、右玉企業(yè)策劃、右玉品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供右玉建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:chinadenli.net

方式一:java代碼實(shí)現(xiàn)

@Override

public boolean onCreateOptionsMenu(Menu menu) {

/**

* 參數(shù)1:組的id

* 參數(shù)2:菜單的id

* 參數(shù)3:排列的順序

* 參數(shù)4:顯示菜單的文本

*/

menu.add(0, 0, 0, "你好");

menu.add(1, 1, 1, "不好");

return super.onCreateOptionsMenu(menu);

}

/**菜單的點(diǎn)擊事件*/

@Override

public boolean onOptionsItemSelected(MenuItem item) {

switch(item.getItemId()){

case 0:

Toast.makeText(this, "你選擇你好", Toast.LENGTH_LONG).show();

break;

case 1:

Toast.makeText(this, "你選擇不好", Toast.LENGTH_LONG).show();

break;

}

}

方式二:xml形式的菜單

步驟一:在res/menu目錄下新建xml文件

menu xmlns:android=""

xmlns:tools=""

tools:context="com.lifei.menu.MainActivity"

item

android:id="@+id/delete_menu_item"

android:orderInCategory="20"

android:title="@string/deletemunu"/

item

android:id="@+id/add_menu_item"

android:orderInCategory="19"

android:title="@string/addmunu"

menu

item

android:id="@+id/add_user_item"

android:orderInCategory="30"

android:title="@string/adduser"/

item

android:id="@+id/add_phone_item"

android:orderInCategory="31"

android:showAsAction="never"

android:title="@string/addhpone"/

/menu

/item

/menu

步驟二:在activity中

@Override

public boolean onCreateOptionsMenu(Menu menu) {

/**xml形式的menu菜單*/

getMenuInflater().inflate(R.menu.main, menu);

return super.onCreateOptionsMenu(menu);

}

點(diǎn)擊事件與方式一是一樣的

android 點(diǎn)擊按鈕時(shí)顯示菜單應(yīng)怎樣實(shí)現(xiàn)?

點(diǎn)擊button彈出對話框菜單

import?android.app.Activity;

import?android.app.AlertDialog;

import?android.content.DialogInterface;

import?android.os.Bundle;

import?android.view.View;

import?android.view.View.OnClickListener;

import?android.widget.Button;

publicclass?choice?extends?Activity?{

private?Button?button;

/**?Called?when?the?activity?is?first?created.?*/

@Override

publicvoid?onCreate(Bundle?savedInstanceState)?{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

button=(Button)findViewById(R.id.button1);

button.setOnClickListener(new?OnClickListener(){

@Override

publicvoid?onClick(View?arg0)?{

new?AlertDialog.Builder(choice.this)

.setTitle("choice")

.setItems(R.array.str_body,?new?DialogInterface.OnClickListener()?{

@Override

publicvoid?onClick(DialogInterface?arg0,?int?arg1)?{

//?TODO?Auto-generated?method?stub

String[]?aryshop=getResources().getStringArray(R.array.str_body);

new?AlertDialog.Builder(choice.this)

.setMessage(aryshop[arg1])

.setNegativeButton("ok",?new?DialogInterface.OnClickListener()?{

@Override

publicvoid?onClick(DialogInterface?arg0,?int?arg1)?{

//?TODO?Auto-generated?method?stub

}

}).show();

}

}).show();

//?TODO?Auto-generated?method?stub

}});

}

}

菜單項(xiàng)

?xmlversion="1.0"encoding="utf-8"?

resources

stringname="hello"Hello?World,?choice!/string

stringname="app_name"ChoiceMenu/string

stringname="strtitle"按我選擇:/string

stringname="str"你選擇的是:/string

arrayname="str_body"

item選項(xiàng)1/item

item選項(xiàng)2/item

item選項(xiàng)3/item

item選項(xiàng)4/item

item選項(xiàng)5/item

item選項(xiàng)6/item

/array

/resources

android中怎么讓menu菜單顯示在屏幕左上角

android 中讓菜單menu顯示在左上角,可以使用popupwindow技術(shù),也就是懸浮菜單,設(shè)置默認(rèn)的位置為左上角,如下代碼:

package?com.example.menutype;

import?android.app.ActionBar.LayoutParams;

import?android.app.Activity;

import?android.content.Context;

import?android.os.Bundle;

import?android.view.Gravity;

import?android.view.LayoutInflater;

import?android.view.Menu;

import?android.view.MenuItem;

import?android.view.View;

import?android.view.View.OnClickListener;

import?android.widget.Button;

import?android.widget.PopupWindow;

import?android.widget.PopupWindow.OnDismissListener;

import?android.widget.TextView;

import?android.widget.Toast;

/**

*?

*?@author?tr

*?@time?2014-3-10

*?@description?自定義菜單,下拉菜單樣式,添加動(dòng)畫效果,重寫onMenuOpened()方法,自定義"menu"按鍵彈出菜單

*/

public?class?MainActivity?extends?Activity?implements?OnClickListener{

private?static?Toast?mToast;

private?static?Context?mContext;

private?PopupWindow?popupWindow?;

private?Button?btn_popupwindow;

private?View?mPopupWindowView;

@Override

protected?void?onCreate(Bundle?savedInstanceState)?{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mContext?=?this;

btn_popupwindow?=?(Button)?findViewById(R.id.btn_popupwindow);

btn_popupwindow.setOnClickListener(this);

initPopupWindow();

}

@Override

public?boolean?onCreateOptionsMenu(Menu?menu)?{

/**actionBar上更多按鈕*/

getMenuInflater().inflate(R.menu.main,?menu);

/**點(diǎn)擊menu,彈出菜單*/

/*

*?

*?add()方法的四個(gè)參數(shù),依次是:

*?

*?1、組別,如果不分組的話就寫Menu.NONE,

*?

*?2、Id,這個(gè)很重要,Android根據(jù)這個(gè)Id來確定不同的菜單

*?

*?3、順序,那個(gè)菜單現(xiàn)在在前面由這個(gè)參數(shù)的大小決定

*?

*?4、文本,菜單的顯示文本

*/

menu.add(Menu.NONE,?Menu.FIRST?+?1,?1,?getResource(R.string.edit_text)).setIcon(

R.drawable.ic_edit);

//?setIcon()方法為菜單設(shè)置圖標(biāo),這里使用的是系統(tǒng)自帶的圖標(biāo),同學(xué)們留意一下,以

//?android.R開頭的資源是系統(tǒng)提供的,我們自己提供的資源是以R開頭的

menu.add(Menu.NONE,?Menu.FIRST?+?2,?2,?getResource(R.string.file)).setIcon(

R.drawable.ic_menu_file);

menu.add(Menu.NONE,?Menu.FIRST?+?3,?3,?getResource(R.string.about)).setIcon(

R.drawable.ic_menu_about);

return?true;

}

/**菜單打開時(shí)調(diào)用*/

@Override

public?boolean?onMenuOpened(int?featureId,?Menu?menu)?{

//?TODO?Auto-generated?method?stub

showToast("menu菜單打開:"+featureId);

//點(diǎn)擊"menu"按鈕打開

if(featureId?==?0){

showPopupWindow();

}

return?super.onMenuOpened(featureId,?menu);//?返回為true?則顯示系統(tǒng)menu

// return?false;

}

/**menu菜單關(guān)閉時(shí)調(diào)用*/

@Override

public?void?onOptionsMenuClosed(Menu?menu)?{

//?TODO?Auto-generated?method?stub

super.onOptionsMenuClosed(menu);

showToast("menu菜單關(guān)閉");

}

@Override

public?boolean?onOptionsItemSelected(MenuItem?item)?{

//?TODO?Auto-generated?method?stub

switch(item.getItemId()){

case?Menu.FIRST?+?1:

case?R.id.action_edit:

showToast(getResource(R.string.edit_text));

break;

case?Menu.FIRST?+?2:

case?R.id.action_file:

showToast(getResource(R.string.file));

break;

case?R.id.action_favorite:

showToast(getResource(R.string.favorite));

break;

case?R.id.action_share:

showToast(getResource(R.string.share));

break;

case?Menu.FIRST?+?3:

case?R.id.action_about:

showToast(getResource(R.string.about));

break;

}

return?super.onOptionsItemSelected(item);

}

@Override

public?void?onClick(View?v)?{

switch(v.getId()){

case?R.id.btn_popupwindow:

showPopupWindow();

break;

case?R.id.textview_about:

showToast(getResource(R.string.about));

popupWindow.dismiss();

break;

case?R.id.textview_edit:

showToast(getResource(R.string.edit_text));

popupWindow.dismiss();

break;

case?R.id.textview_file:

showToast(getResource(R.string.file));

popupWindow.dismiss();

break;

}

}

/**顯示popupwindow*/

private?void?showPopupWindow(){

if(!popupWindow.isShowing()){

popupWindow.showAsDropDown(btn_popupwindow,?btn_popupwindow.getLayoutParams().width/2,?0);

}else{

popupWindow.dismiss();

}

}

/**

*?初始化popupwindow

*/

private?void?initPopupWindow(){

initPopupWindowView();

//初始化popupwindow,綁定顯示view,設(shè)置該view的寬度/高度

popupWindow?=?new?PopupWindow(mPopupWindowView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

popupWindow.setFocusable(true);

popupWindow.setOutsideTouchable(true);

//?這個(gè)是為了點(diǎn)擊“返回Back”也能使其消失,并且并不會(huì)影響你的背景;使用該方法點(diǎn)擊窗體之外,才可關(guān)閉窗體

popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bitmap_book_read_chapterlist_repeat));

//Background不能設(shè)置為null,dismiss會(huì)失效

// popupWindow.setBackgroundDrawable(null);

//設(shè)置漸入、漸出動(dòng)畫效果

// popupWindow.setAnimationStyle(R.style.popupwindow);

popupWindow.update();

//popupWindow調(diào)用dismiss時(shí)觸發(fā),設(shè)置了setOutsideTouchable(true),點(diǎn)擊view之外/按鍵back的地方也會(huì)觸發(fā)

popupWindow.setOnDismissListener(new?OnDismissListener()?{

@Override

public?void?onDismiss()?{

//?TODO?Auto-generated?method?stub

// showToast("關(guān)閉popupwindow");

}

});

}

當(dāng)前標(biāo)題:android菜單,Android菜單組件
文章出自:http://chinadenli.net/article7/dsgdsij.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)網(wǎng)站設(shè)計(jì)公司Google微信公眾號服務(wù)器托管做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司