当前位置:首页 » 安卓系统 » 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 05:21:09 浏览:347
4款配置怎么选 发布:2024-05-21 05:20:03 浏览:585
python服务重启 发布:2024-05-21 05:07:51 浏览:667
内部存储空间怎么清除 发布: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