當前位置:首頁 » 安卓系統 » android中的menu

android中的menu

發布時間: 2024-05-10 20:56:15

㈠ menu鍵是什麼意思

menu鍵是菜單鍵。又稱Menu菜單,一般在手機屏幕下方三個按鍵中的一個。

安卓手機必備的主要按鍵,很多主要的設置都需要通過Menu鍵來激活,比如要打開Android系統的設置,或更改壁紙,就需要在手機桌面按住Menu鍵。

菜單鍵概述:

菜單,將系統可以執行的命令以階層的方式顯示出來的一個界面。一般置於畫面的最上方或者最下方,應用程序能使用的所有命令幾乎全部都能放入。重要程度一般是從左到右,越往右重要度越低。

命定的層次根據應用程序的不同而不同,一般重視文件的操作、編輯功能,因此放在最左邊,然後往右有各種設置等操作,最右邊往往設有幫助。一般使用滑鼠的第一按鈕進行操作。

即時菜單(又稱功能表、上下文菜單(Context Menu)),與應用程序准備好的層次菜單不同,在菜單欄以外的地方,通過滑鼠的第二按鈕調出的菜單稱為「即時菜單」。根據調出位置的不同,菜單內容即時變化,列出所指示的對象可以進行的操作。

㈡ 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中menu可能需要重寫的方法是哪些

可能需要重寫的如下:
public boolean onCreateOptionsMenu(Menu menu)方法只被系統調用一次,如需要動態更改菜單內容還需重寫onPrepareOptionsMenu(Menu menu)方法實現

[java] view plain
Menu m=null;
int count=0;

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

if(count>0){
if(count%2==0){
menu.removeGroup(1);
}else{
menu.add(1, Menu.FIRST, 0, "5st");
menu.add(1, Menu.FIRST+1, 0, "6st");
}
}
count++;
return super.onPrepareOptionsMenu(menu);
}

2,context menu(長按屏幕產生)

[java] view plain
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
Toast.makeText(this, "you select"+item.getItemId(), 500).show();
break;
case 2:
Toast.makeText(this, "you select"+item.getItemId(), 500).show();
break;
}
return super.onContextItemSelected(item);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.add(0, Menu.FIRST, 0, "1st");
menu.add(0, Menu.FIRST+1, 0, "2st");
super.onCreateContextMenu(menu, v, menuInfo);
}

㈣ android menu 怎麼得到item

android 中的menu一般是指上下文菜單或者是選項菜單

其中上選項菜單是可以在布局中res下的menu中在xml布局中寫好布局來的然後通過java代碼中的onCreateOptionsMenu來載入選項菜單,android4.4高級版本後是自動把菜單載入到標題欄上的,而不是低版本的按下menu鍵才顯是出來的,上下文菜單是是通過onCreateContextMenu這個方法來注冊上下文菜單的

下面講講如何獲取menu中的item

獲取上下文菜單的item其實就是當單機選項菜單時會觸發這個方法

(MenuItemmi){
//判斷單擊的是哪個菜單項,並針對性的作出響應。
switch(mi.getItemId()){
caseFONT_RED:
title.setTextColor(Color.RED);
break;
caseFONT_GREEN:
title.setTextColor(Color.GREEN);
break;
caseFONT_BLUE:
title.setTextColor(Color.BLUE);
break;
caseMENU1:
createdialog();
break;
}
returntrue;
}

獲取選項菜單的item其實就是當單擊選項菜單時會觸發這個方法

(intfeatureId,MenuItemitem){
//利用switch根據ItemId區分點擊的是哪個菜單以便正確響應用戶操作
MenuItemtemp=item;
switch(item.getItemId()){
caseR.id.rename:
createdialog();
break;
caseR.id.red:
title.setTextColor(Color.RED);
break;
caseR.id.green:
title.setTextColor(Color.GREEN);
break;
caseR.id.blue:
title.setTextColor(Color.BLUE);
break;
// caseR.id.choose_color:
// createpopupmenu(temp);
// break;
}
returnsuper.onMenuItemSelected(featureId,item);
}
熱點內容
內部存儲空間怎麼清除 發布:2024-05-21 04:04:55 瀏覽:498
bilibili不能緩存 發布:2024-05-21 03:31:14 瀏覽:617
解壓剃發 發布:2024-05-21 03:16:27 瀏覽:641
伺服器怎麼連接到電腦顯示屏上 發布:2024-05-21 02:38:21 瀏覽:286
織夢安裝資料庫連接失敗 發布:2024-05-21 02:37:45 瀏覽:259
python編程入門經典pdf 發布:2024-05-21 02:31:45 瀏覽:7
arm編譯添加驅動 發布:2024-05-21 02:02:28 瀏覽:476
安卓設置頁面是怎麼 發布:2024-05-21 01:32:51 瀏覽:521
學生成績管理系統資料庫設計 發布:2024-05-21 01:14:41 瀏覽:43
我的世界什麼指令直接出現伺服器 發布:2024-05-21 01:10:00 瀏覽:397