導航:首頁 > 操作系統 > android折疊菜單

android折疊菜單

發布時間:2022-10-31 12:00:12

android 怎麼實現左側推出導航菜單

Android左側推出導航菜單可以讓Activity繼承PopupWindow類來實現的彈出窗體,布局可以根據自己定義設計。彈出效果主要使用了translate和alpha樣式實現。具體的做法是下列代碼:

java">第一步:設計彈出窗口xml:

Xml代碼
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
>

<LinearLayout
android:id="@+id/pop_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:background="@drawable/btn_style_alert_dialog_background"
>


<Button
android:id="@+id/btn_take_photo"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="20dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="拍照"
android:background="@drawable/btn_style_alert_dialog_button"
android:textStyle="bold"
/>

<Button
android:id="@+id/btn_pick_photo"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="從相冊選擇"
android:background="@drawable/btn_style_alert_dialog_button"
android:textStyle="bold"
/>

<Button
android:id="@+id/btn_cancel"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="15dip"
android:layout_marginBottom="15dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="取消"
android:background="@drawable/btn_style_alert_dialog_cancel"
android:textColor="#ffffff"
android:textStyle="bold"

/>
</LinearLayout>
</RelativeLayout>
第二步:創建SelectPicPopupWindow類繼承PopupWindow:

Java代碼
importandroid.app.Activity;
importandroid.content.Context;
importandroid.graphics.drawable.ColorDrawable;
importandroid.view.LayoutInflater;
importandroid.view.MotionEvent;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.view.View.OnTouchListener;
importandroid.view.ViewGroup.LayoutParams;
importandroid.widget.Button;
importandroid.widget.PopupWindow;

{


privateButtonbtn_take_photo,btn_pick_photo,btn_cancel;
privateViewmMenuView;

publicSelectPicPopupWindow(Activitycontext,OnClickListeneritemsOnClick){
super(context);
LayoutInflaterinflater=(LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mMenuView=inflater.inflate(R.layout.alert_dialog,null);
btn_take_photo=(Button)mMenuView.findViewById(R.id.btn_take_photo);
btn_pick_photo=(Button)mMenuView.findViewById(R.id.btn_pick_photo);
btn_cancel=(Button)mMenuView.findViewById(R.id.btn_cancel);
//取消按鈕
btn_cancel.setOnClickListener(newOnClickListener(){

publicvoidonClick(Viewv){
//銷毀彈出框
dismiss();
}
});
//設置按鈕監聽
btn_pick_photo.setOnClickListener(itemsOnClick);
btn_take_photo.setOnClickListener(itemsOnClick);
//設置SelectPicPopupWindow的View
this.setContentView(mMenuView);
//設置SelectPicPopupWindow彈出窗體的寬
this.setWidth(LayoutParams.FILL_PARENT);
//設置SelectPicPopupWindow彈出窗體的高
this.setHeight(LayoutParams.WRAP_CONTENT);
//設置SelectPicPopupWindow彈出窗體可點擊
this.setFocusable(true);
//設置SelectPicPopupWindow彈出窗體動畫效果
this.setAnimationStyle(R.style.AnimBottom);
//實例化一個ColorDrawable顏色為半透明
ColorDrawabledw=newColorDrawable(0xb0000000);
//設置SelectPicPopupWindow彈出窗體的背景
this.setBackgroundDrawable(dw);
//mMenuView添加OnTouchListener監聽判斷獲取觸屏位置如果在選擇框外面則銷毀彈出框
mMenuView.setOnTouchListener(newOnTouchListener(){

publicbooleanonTouch(Viewv,MotionEventevent){

intheight=mMenuView.findViewById(R.id.pop_layout).getTop();
inty=(int)event.getY();
if(event.getAction()==MotionEvent.ACTION_UP){
if(y<height){
dismiss();
}
}
returntrue;
}
});

}

}

第三步:編寫MainActivity類實現測試:

Java代碼
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.Gravity;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.TextView;

{

//自定義的彈出框類
;

@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextViewtv=(TextView)this.findViewById(R.id.text);
//把文字控制項添加監聽,點擊彈出自定義窗口
tv.setOnClickListener(newOnClickListener(){
publicvoidonClick(Viewv){
//實例化SelectPicPopupWindow
menuWindow=newSelectPicPopupWindow(MainActivity.this,itemsOnClick);
//顯示窗口
menuWindow.showAtLocation(MainActivity.this.findViewById(R.id.main),Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL,0,0);//設置layout在PopupWindow中顯示的位置
}
});
}

//為彈出窗口實現監聽類
=newOnClickListener(){

publicvoidonClick(Viewv){
menuWindow.dismiss();
switch(v.getId()){
caseR.id.btn_take_photo:
break;
caseR.id.btn_pick_photo:
break;
default:
break;
}


}

};

}

上述的代碼實現了從底部彈出,也可以根據PopupWindow類設置從左下部彈出。

Android的對話框有兩種:PopupWindow和AlertDialog。它們的不同點在於:

AlertDialog的位置固定,而PopupWindow的位置可以隨意

AlertDialog是非阻塞線程的,而PopupWindow是阻塞線程的

PopupWindow的位置按照有無偏移分,可以分為偏移和無偏移兩種;按照參照物的不同,可以分為相對於某個控制項(Anchor錨)和相對於父控制項。具體如下

showAsDropDown(View anchor):相對某個控制項的位置(正左下方),無偏移

showAsDropDown(View anchor, int xoff, int yoff):相對某個控制項的位置,有偏移

showAtLocation(View parent, int gravity, int x, int y):相對於父控制項的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以設置偏移或無偏移

Ⅱ android如何彈出一個占屏幕一半的菜單

android彈出一個占屏幕一半的菜單,可以使用popupwindow,設置彈出的xy軸的距離占據屏幕一半即可,如下代碼:

packagecom.example.hellopopupwindow;

importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.content.Context;
importandroid.util.Log;
importandroid.view.LayoutInflater;
importandroid.view.MotionEvent;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.view.View.OnTouchListener;
importandroid.view.ViewGroup.LayoutParams;
importandroid.widget.Button;
importandroid.widget.PopupWindow;
importandroid.widget.Toast;

{

privateContextmContext=null;

@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mContext=this;

Buttonbutton=(Button)findViewById(R.id.button);
button.setOnClickListener(newView.OnClickListener(){

@Override
publicvoidonClick(Viewview){

showPopupWindow(view);
}
});
}

privatevoidshowPopupWindow(Viewview){

//一個自定義的布局,作為顯示的內容
ViewcontentView=LayoutInflater.from(mContext).inflate(
R.layout.pop_window,null);
//設置按鈕的點擊事件
Buttonbutton=(Button)contentView.findViewById(R.id.button1);
button.setOnClickListener(newOnClickListener(){

@Override
publicvoidonClick(Viewv){
Toast.makeText(mContext,"buttonispressed",
Toast.LENGTH_SHORT).show();
}
});

finalPopupWindowpopupWindow=newPopupWindow(contentView,
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,true);

popupWindow.setTouchable(true);

popupWindow.setTouchInterceptor(newOnTouchListener(){

@Override
publicbooleanonTouch(Viewv,MotionEventevent){

Log.i("mengdd","onTouch:");

returnfalse;
//這里如果返回true的話,touch事件將被攔截
//攔截後PopupWindow的onTouchEvent不被調用,這樣點擊外部區域無法dismiss
}
});

//如果不設置PopupWindow的背景,無論是點擊外部區域還是Back鍵都無法dismiss彈框
//我覺得這里是API的一個bug
popupWindow.setBackgroundDrawable(getResources().getDrawable(
R.drawable.selectmenu_bg_downward));

//設置好參數之後再show
popupWindow.showAsDropDown(view);

}

}

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

用慣了Android的人在剛拿到iPhone的時候,總是會習慣性的用手指從狀態欄往下拖一下,這都是給Notification鬧的。
不過Notification也確實是1個不錯的提示工具,不幹擾正常的操作,事後還可以再翻看詳細的內容,點擊後還可以進入相關的畫面查看更具體的內容。
今天我就以代碼為主的形式來介紹Notification的使用,包括基本用法,自定義的View,以及更多的控制方法。
另一種Android中常用到的提示方法Toast的用法請參見《教程:在Android中使用Toast進行提示》
我們先看下Notification的幾個主要組成部分:
Icon:不解釋
Ticker Text:Notification剛出來的時候,在狀態欄上滾動的字幕,如果很長,會自動分割滾動

Content Title:Notification展開後的標題
Content Text:Notification展開後的內容

Notification的一般用法
取得NotificationManager
private NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
創建Notification並且顯示
//Notification的滾動提示
String tickerText = "My notification, It's a long text! Hello World desiyo?";
//Notification的圖標,一般不要用彩色的
int icon = R.drawable.icon_02241_3;

//contentTitle和contentText都是標準的Notification View的內容
//Notification的內容標題,拖下來後看到的標題
String contentTitle="My notification";
//Notification的內容
String contentText="Hello World!";

//Notification的Intent,即點擊後轉向的Activity
Intent notificationIntent = new Intent(this, this.getClass());
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

//創建Notifcation
Notification notification = new Notification(icon, tickerText, System.currentTimeMillis());
//設定Notification出現時的聲音,一般不建議自定義
notification.defaults |= Notification.DEFAULT_SOUND;
//設定如何振動
notification.defaults |= Notification.DEFAULT_VIBRATE;
//指定Flag,Notification.FLAG_AUTO_CANCEL意指點擊這個Notification後,立刻取消自身
//這符合一般的Notification的運作規范
notification.flags|=Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
//顯示這個notification
mNotificationManager.notify(HELLO_ID, notification);
這是最基本的應用,可以說除了找個合適的圖標以外,其它都很簡單。

使用自定義View的Notification
同Toast一樣,我們也可以自已指定1個View來作為Notification展開後的顯示內容,比如說在Android Market中下載的時候,Notification中會顯示當前下載的進度,那麼我們也來模擬1個這樣的效果吧。
首先給出View的定義文件:notification_view_sample.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp"
>
<ImageView android:id="@+id/notificationImage"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@android:drawable/stat_sys_download"
/>
<TextView android:id="@+id/notificationTitle"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@id/notificationImage"
android:layout_alignParentRight="true"
android:paddingLeft="6dp"
android:textColor="#FF000000"
/>
<TextView android:id="@+id/notificationPercent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/notificationImage"
android:paddingTop="2dp"
android:textColor="#FF000000"
/>
<ProgressBar android:id="@+id/notificationProgress"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/notificationTitle"
android:layout_alignLeft="@id/notificationTitle"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/notificationPercent"
android:paddingLeft="6dp"
android:paddingRight="3dp"
android:paddingTop="2dp"
style="?android:attr/progressBarStyleHorizontal"
/>
</RelativeLayout>
RelativeLayout的使用,可以參考:《教程:Android各種Layout特性和使用匯總(一)》

Ⅳ Android中怎麼實現底部菜單欄

一共兩種實現方式:

方式一:java代碼實現
@Override
public boolean onCreateOptionsMenu(Menu menu) {
/**
* 參數1:組的id
* 參數2:菜單的id
* 參數3:排列的順序
* 參數4:顯示菜單的文本
*/
menu.add(0, 0, 0, "你好");
menu.add(1, 1, 1, "不好");

return super.onCreateOptionsMenu(menu);
}

/**菜單的點擊事件*/
@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="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/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/adser"/>
<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);
}

點擊事件與方式一是一樣的

Ⅳ android的自定圓盤菜單怎麼做

1、通用模式

上圖是圖片加文字,如果我想換成按鈕呢,或者我只需要圖片。這里就需要定製。怎麼辦呢,我採用了適配模式,大家都還記得 ListView的用法,我這里也借鑒了一下:

public void setAdapter(ListAdapter mAdapter) { this.mAdapter = mAdapter;
}123

這樣就可以實現Menu的高度定製。

2、構建菜單項

代碼參考buildMenuItems(),對mAdapter遍歷獲取子View,添加點擊事件,調用addView()添加到ViewGroup,這個時候系統就會調用onMeasure()對子View計算大小。

3、計算item大小

代碼參考measureMyself()和measureChildViews(),確定每個item的尺寸大小。

4、item布局

首先計算item(x,y)距離圓心的長度,我畫了一個草圖:

需要重寫onTouchEvent()方法,並把返回值改為true。處理手勢按下(ACTION_DOWN),抬起(ACTION_UP)的狀態。

首先我們要判斷手指按下是否在陰影局域內。注意手指按下是指尖局域與屏幕接觸,並不是一點,所以有誤差。

x = event.getX();
y = event.getY();if ((x - 圓心x) * (x - 圓心x) + (y - 圓心y) * (y - 圓心y) < (圓心x+ 誤差) * (圓心y+ 誤差)) {
isRange = true;
}12345

然後我們要計算運動的速度,我剛開始的想法是用重力加速度,非常感謝我同事小賈,他給了我更好的意見:速度=距離/時間。

ACTION_DOWN:

lastTouchTime = System.currentTimeMillis();1

ACTION_UP:

long timeStamp = System.currentTimeMillis() - lastTouchTime;float distance = (float) Math.sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)); float speed = distance / timeStamp;123

然後我們通過對比手指按下的x的坐標,和抬起x的坐標,來判斷用戶是向左滑,還是右滑。

if (x1 - x > 0) {
isLeft = false;
} else {
isLeft = true;
}12345

最後通過handler來改變每次運動的角度,使Menu很自然的旋轉了起來:

if (isLeft) { //向左轉動
offsetRotation -= ANGLE;
} else { //向右轉動
offsetRotation += ANGLE;
} //速度衰減
speed -= SPEED_ATTENUATION;
invalidate();//重繪
handler.sendEmptyMessageDelayed(EMPTY_MESSAGE, 50);1234567891011

使用

1、xml布局

<com.github.ws.viewdemo.widget.CircleMenuLayout
android:id="@+id/cm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f0f0">

</com.github.ws.viewdemo.widget.CircleMenuLayout>1234567

2、class文件

circleMenuLayout.setAdapter(new MyAdapter());

circleMenuLayout.setOnItemClickListener(new CircleMenuLayout.OnItemClickListener() {
@Override public void onItemClickListener(View v, int position) {
Toast.makeText(MainActivity.this, mList.get(position).text + "", Toast.LENGTH_SHORT).show();
}
});12345678

源碼我已上傳到github,地址https://github.com/HpWens/ViewDemo,再一次感謝大家的關注。

Ⅵ android 平鋪菜單實現方式 用什麼控制項

這個,當菜單來用的話,基本應該是tablelayout 和tablerow來做,裡面用imageview或者組合控制項來做,反正菜單項是固定個數的

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

android 中讓菜單menu顯示在左上角,可以使用popupwindow技術,也就是懸浮菜單,設置默認的位置為左上角

Ⅷ android 怎麼實現點擊菜單在頂部和底部同時呼出不同的菜單選項

菜單是用戶界面中最常見的元素之一,使用非常頻繁,在Android中,菜單被分為如下三種,選項菜單(OptionsMenu)、上下文菜單(ContextMenu)和子菜單(SubMenu),以下說的是創建OptionsMenu

一、概述

public boolean onCreateOptionsMenu(Menu menu):使用此方法調用OptionsMenu。

public boolean onOptionsItemSelected(MenuItem item):選中菜單項後發生的動作。

public void onOptionsMenuClosed(Menu menu):菜單關閉後發生的動作。

public boolean onPrepareOptionsMenu(Menu menu):選項菜單顯示之前onPrepareOptionsMenu方法會被調用,你可以用此方法來根據打當時的情況調整菜單。

public boolean onMenuOpened(int featureId, Menu menu):單打開後發生的動作。

二、默認樣式

默認樣式是在屏幕底部彈出一個菜單,這個菜單我們就叫他選項菜單OptionsMenu,一般情況下,選項菜單最多顯示2排每排3個菜單項,這些菜單項有文字有圖標,也被稱作Icon Menus,如果多於6項,從第六項開始會被隱藏,在第六項會出現一個More里,點擊More才出現第六項以及以後的菜單項,這些菜單項也被稱作Expanded Menus。下面介紹。

1.main.xml

<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextViewandroid:layout_width="wrap_content"
android:layout_height="wrap_content"android:text="請點擊Menu鍵顯示選項菜單"
android:id="@+id/TextView02"/>

</LinearLayout>


2。重載onCreateOptionsMenu(Menu menu)方法

重載onCreateOptionsMenu(Menu menu)方法,並在此方法中添加菜單項,最後返回true,如果false,菜單則不會顯示。

(Menumenu)

@Override
(Menumenu){
/*
*
*add()方法的四個參數,依次是:
*
*1、組別,如果不分組的話就寫Menu.NONE,
*
*2、Id,這個很重要,Android根據這個Id來確定不同的菜單
*
*3、順序,那個菜單現在在前面由這個參數的大小決定
*
*4、文本,菜單的顯示文本
*/

menu.add(Menu.NONE,Menu.FIRST+1,5,"刪除").setIcon(

android.R.drawable.ic_menu_delete);

//setIcon()方法為菜單設置圖標,這里使用的是系統自帶的圖標,同學們留意一下,以

//android.R開頭的資源是系統提供的,我們自己提供的資源是以R開頭的

menu.add(Menu.NONE,Menu.FIRST+2,2,"保存").setIcon(

android.R.drawable.ic_menu_edit);

menu.add(Menu.NONE,Menu.FIRST+3,6,"幫助").setIcon(

android.R.drawable.ic_menu_help);

menu.add(Menu.NONE,Menu.FIRST+4,1,"添加").setIcon(

android.R.drawable.ic_menu_add);

menu.add(Menu.NONE,Menu.FIRST+5,4,"詳細").setIcon(

android.R.drawable.ic_menu_info_details);

menu.add(Menu.NONE,Menu.FIRST+6,3,"發送").setIcon(

android.R.drawable.ic_menu_send);

returntrue;

}

3。為菜單項注冊事件

使用onOptionsItemSelected(MenuItem item)方法為菜單項注冊事件

(MenuItemitem)

@Override
(MenuItemitem){
switch(item.getItemId()){

caseMenu.FIRST+1:

Toast.makeText(this,"刪除菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+2:

Toast.makeText(this,"保存菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+3:

Toast.makeText(this,"幫助菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+4:

Toast.makeText(this,"添加菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+5:

Toast.makeText(this,"詳細菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+6:

Toast.makeText(this,"發送菜單被點擊了",Toast.LENGTH_LONG).show();

break;

}

returnfalse;

}

4.完整代碼

packagecom.android.menu;

importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.Menu;
importandroid.view.MenuItem;
importandroid.widget.Toast;

{
/**.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

@Override
(Menumenu){
/*
*
*add()方法的四個參數,依次是:
*
*1、組別,如果不分組的話就寫Menu.NONE,
*
*2、Id,這個很重要,Android根據這個Id來確定不同的菜單
*
*3、順序,那個菜單現在在前面由這個參數的大小決定
*
*4、文本,菜單的顯示文本
*/

menu.add(Menu.NONE,Menu.FIRST+1,5,"刪除").setIcon(

android.R.drawable.ic_menu_delete);

//setIcon()方法為菜單設置圖標,這里使用的是系統自帶的圖標,同學們留意一下,以

//android.R開頭的資源是系統提供的,我們自己提供的資源是以R開頭的

menu.add(Menu.NONE,Menu.FIRST+2,2,"保存").setIcon(

android.R.drawable.ic_menu_edit);

menu.add(Menu.NONE,Menu.FIRST+3,6,"幫助").setIcon(

android.R.drawable.ic_menu_help);

menu.add(Menu.NONE,Menu.FIRST+4,1,"添加").setIcon(

android.R.drawable.ic_menu_add);

menu.add(Menu.NONE,Menu.FIRST+5,4,"詳細").setIcon(

android.R.drawable.ic_menu_info_details);

menu.add(Menu.NONE,Menu.FIRST+6,3,"發送").setIcon(

android.R.drawable.ic_menu_send);

returntrue;

}

@Override
(MenuItemitem){
switch(item.getItemId()){

caseMenu.FIRST+1:

Toast.makeText(this,"刪除菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+2:

Toast.makeText(this,"保存菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+3:

Toast.makeText(this,"幫助菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+4:

Toast.makeText(this,"添加菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+5:

Toast.makeText(this,"詳細菜單被點擊了",Toast.LENGTH_LONG).show();

break;

caseMenu.FIRST+6:

Toast.makeText(this,"發送菜單被點擊了",Toast.LENGTH_LONG).show();

break;

}

returnfalse;

}

@Override
publicvoidonOptionsMenuClosed(Menumenu){
Toast.makeText(this,"選項菜單關閉了",Toast.LENGTH_LONG).show();
}

@Override
(Menumenu){
Toast.makeText(this,
"選項菜單顯示之前onPrepareOptionsMenu方法會被調用,你可以用此方法來根據打當時的情況調整菜單",
Toast.LENGTH_LONG).show();

//如果返回false,此方法就把用戶點擊menu的動作給消費了,onCreateOptionsMenu方法將不會被調用

returntrue;

}
}

5.運行效果

Ⅸ Android 中的宮格菜單是如何實現的

那是wp8系統專用的界面,安卓也有模仿的,你可以找wp8界面就好了

閱讀全文

與android折疊菜單相關的資料

熱點內容
匯編程序員待遇 瀏覽:357
怎麼批量有順序的命名文件夾 瀏覽:209
杭州程序員健身 瀏覽:17
dvd光碟存儲漢子演算法 瀏覽:758
蘋果郵件無法連接伺服器地址 瀏覽:963
phpffmpeg轉碼 瀏覽:672
長沙好玩的解壓項目 瀏覽:145
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:737
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:486
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:383
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:350
風翼app為什麼進不去了 瀏覽:779
im4java壓縮圖片 瀏覽:362