1.Menu(菜单)
a.OptionMenu(选项菜单)
核心方法:
onCreateOptionMenu//选项菜单创建前调用
onMenuOpened//菜单打开前调用
onOptionsItemSelected//选项菜单选中时调用
onOptionsMenuClosed//选项菜单关闭前调用
onPrepareOptionsMenu//选项菜单显示前调用
b.ContextMenu(上下文菜单)
核心方法:
onCreateContextMenu//创建菜单
onContextItemSelected//响应选中的事件
c.SubMenu(子菜单)
核心方法:
addSubMenu//添加子菜单
2.Dialog对话框
有三个子类:
ProgressDialog
DatePickerDialog
TimePickerDialog
a.AlertDialog(警告对话框)
三个按钮:
setPositiveButton
setNegativeButton
setNeutralButton
b.ProgressDialog
核心API:
final ProgressDialog progress = new ProgressDialog(this);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setMax(100);
progress.setProgress(40);
progress.show();
new Thread(){
@Override
public void run() {
int p = 1;
while(true){
p++;
progress.setProgress(p);
if(p >= 100){
progress.dismiss();
}
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}.start();
C.DatePickerDialog
核心API:
DatePickerDialog dialog = new DatePickerDialog(this,new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
System.out.println(year+"-"+monthOfYear+"-"+dayOfMonth);
}
},2011,12,18);
/**显示对话框*/
dialog.show();
错误:current should be >= start and <= end
d.TimePickerDialog
核心API:
TimePickerDialog dialog = new TimePickerDialog(this,new OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
System.out.println(hourOfDay+"-"+minute);
}
/**20是小时,此时表示的19点03分,true是表示使用24小时制*/
},20,3,true);
a.OptionMenu(选项菜单)
核心方法:
onCreateOptionMenu//选项菜单创建前调用
onMenuOpened//菜单打开前调用
onOptionsItemSelected//选项菜单选中时调用
onOptionsMenuClosed//选项菜单关闭前调用
onPrepareOptionsMenu//选项菜单显示前调用
b.ContextMenu(上下文菜单)
核心方法:
onCreateContextMenu//创建菜单
onContextItemSelected//响应选中的事件
c.SubMenu(子菜单)
核心方法:
addSubMenu//添加子菜单
2.Dialog对话框
有三个子类:
ProgressDialog
DatePickerDialog
TimePickerDialog
a.AlertDialog(警告对话框)
三个按钮:
setPositiveButton
setNegativeButton
setNeutralButton
b.ProgressDialog
核心API:
final ProgressDialog progress = new ProgressDialog(this);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setMax(100);
progress.setProgress(40);
progress.show();
new Thread(){
@Override
public void run() {
int p = 1;
while(true){
p++;
progress.setProgress(p);
if(p >= 100){
progress.dismiss();
}
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}.start();
C.DatePickerDialog
核心API:
DatePickerDialog dialog = new DatePickerDialog(this,new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
System.out.println(year+"-"+monthOfYear+"-"+dayOfMonth);
}
},2011,12,18);
/**显示对话框*/
dialog.show();
错误:current should be >= start and <= end
d.TimePickerDialog
核心API:
TimePickerDialog dialog = new TimePickerDialog(this,new OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
System.out.println(hourOfDay+"-"+minute);
}
/**20是小时,此时表示的19点03分,true是表示使用24小时制*/
},20,3,true);
dialog.show();
学习源码:http://download.csdn.net/detail/qq1059458376/4695775
本文详细介绍了 Android 开发中常用的 UI 控件,包括菜单(Menu)、选项菜单(OptionMenu)、上下文菜单(ContextMenu)、子菜单(SubMenu)以及对话框(Dialog)。其中,深入探讨了对话框的各种类型,如警告对话框(AlertDialog)、进度对话框(ProgressDialog)、日期选择对话框(DatePickerDialog)和时间选择对话框(TimePickerDialog),并提供了示例代码。
&spm=1001.2101.3001.5002&articleId=8121284&d=1&t=3&u=0146042ca79e4bf3a43cea764d56ace6)
1268

被折叠的 条评论
为什么被折叠?



