Dialog 各种风格使用
来源:互联网 发布:清华五道口考研知乎 编辑:程序博客网 时间:2024/05/18 02:43
import android.app.AlertDialog;import android.app.DatePickerDialog;import android.app.Dialog;import android.app.ProgressDialog;import android.content.Context;import android.content.DialogInterface;import android.os.Build;import android.os.Bundle;import android.support.annotation.RequiresApi;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.DatePicker;import android.widget.EditText;import android.widget.RelativeLayout;import android.widget.Toast;import java.util.Calendar;import butterknife.BindView;import butterknife.ButterKnife;import butterknife.OnClick;public class MainActivity extends AppCompatActivity { @BindView(R.id.button) Button button; @BindView(R.id.button2) Button button2; @BindView(R.id.button3) Button button3; @BindView(R.id.button4) Button button4; @BindView(R.id.button5) Button button5; @BindView(R.id.button6) Button button6; @BindView(R.id.button7) Button button7; @BindView(R.id.button8) Button button8; @BindView(R.id.activity_main) RelativeLayout activityMain; Context context; private int year; private int month; private int day; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); context = this; } @RequiresApi(api = Build.VERSION_CODES.N) @OnClick({R.id.button, R.id.button2, R.id.button3, R.id.button4, R.id.button5, R.id.button6, R.id.button7, R.id.button8}) public void onClick(View view) { switch (view.getId()) { case R.id.button: Dialog dialog = new Dialog(this); dialog.setTitle("Dialog"); dialog.setCanceledOnTouchOutside(true); dialog.show(); break; case R.id.button2: Dialog dialog1 = new AlertDialog.Builder(context).setTitle("AlertBuilder"). setMessage("测试测试测试车市速度发顺丰").setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "取消了", Toast.LENGTH_SHORT).show(); } }).setNeutralButton("中间", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "中间取消了", Toast.LENGTH_SHORT).show(); } }).setPositiveButton("确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "确定", Toast.LENGTH_SHORT).show(); } }).create(); dialog1.show(); break; case R.id.button3: Dialog dialog2 = new android.support.v7.app.AlertDialog.Builder(context).setTitle("AlertBuilder"). setMessage("测试测试测试车市速度发车市速度发顺丰").setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "取消了", Toast.LENGTH_SHORT).show(); } }).setNeutralButton("中间", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "中间取消了", Toast.LENGTH_SHORT).show(); } }).setPositiveButton("确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "确定", Toast.LENGTH_SHORT).show(); } }).setIcon(R.mipmap.ic_launcher).create(); dialog2.show(); break; case R.id.button4: Dialog dialog3 = new android.support.v7.app.AlertDialog.Builder(context).setTitle("输入框"). setView(new EditText(context)).setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "取消了", Toast.LENGTH_SHORT).show(); } }).setPositiveButton("确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "确定", Toast.LENGTH_SHORT).show(); } }).setIcon(R.mipmap.ic_launcher).create(); dialog3.show(); break; case R.id.button5: final String[] str = new String[]{"item1", "item2"}; Dialog dialog4 = new android.support.v7.app.AlertDialog.Builder(context).setTitle("单选框"). setMultiChoiceItems(str, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { StringBuffer sb = new StringBuffer(); if (isChecked) { sb.append(str[which].toString() + ","); } Toast.makeText(context, sb.toString(), Toast.LENGTH_SHORT).show(); } }). setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "取消了", Toast.LENGTH_SHORT).show(); } }).setPositiveButton("确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, "确定", Toast.LENGTH_SHORT).show(); } }).setIcon(R.mipmap.ic_launcher).create(); dialog4.show(); break; case R.id.button6: final ProgressDialog dialog5 = new ProgressDialog(context); dialog5.setMessage("下载最新apk"); dialog5.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog5.setMax(100); dialog5.show(); new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub int i = 0; while (i < 100) { try { Thread.sleep(200); // 更新进度条的进度,可以在子线程中更新进度条进度 dialog5.incrementProgressBy(1); // dialog.incrementSecondaryProgressBy(10)//二级进度条更新方式 i++; } catch (Exception e) { // TODO: handle exception } } // 在进度条走完时删除Dialog dialog5.dismiss(); } }).start(); break; case R.id.button7: //初始化Calendar日历对象 Calendar mycalendar = Calendar.getInstance(); //获取Calendar对象中的年 year = mycalendar.get(Calendar.YEAR); //获取Calendar对象中的月 month = mycalendar.get(Calendar.MONTH); //获取这个月的第几天 day = mycalendar.get(Calendar.DAY_OF_MONTH); Toast.makeText(context, "当前日期:" + year + "-" + (month + 1) + "-" + day, Toast.LENGTH_SHORT).show(); DatePickerDialog dialog6 = new DatePickerDialog(context, Datelistener, year, month, day); dialog6.show();//显示DatePickerDialog组件 break; case R.id.button8: break; } } private DatePickerDialog.OnDateSetListener Datelistener = new DatePickerDialog.OnDateSetListener() { /**params:view:该事件关联的组件 * params:myyear:当前选择的年 * params:monthOfYear:当前选择的月 * params:dayOfMonth:当前选择的日 */ @Override public void onDateSet(DatePicker view, int myyear, int monthOfYear, int dayOfMonth) { //修改year、month、day的变量值,以便以后单击按钮时,DatePickerDialog上显示上一次修改后的值 year = myyear; month = monthOfYear; day = dayOfMonth; //更新日期 updateDate(); } //当DatePickerDialog关闭时,更新日期显示 private void updateDate() { //在TextView上显示日期 Toast.makeText(context, "当前日期:" + year + "-" + (month + 1) + "-" + day, Toast.LENGTH_SHORT).show(); } };}
0 0
- Dialog 各种风格使用
- 【Android】自定义风格的各种dialog
- 各种Dialog的使用
- Dialog的各种使用方式
- 使用PopupWindow完成各种dialog
- [Android] Material 风格的 Dialog 的使用
- [Android] Material 风格的 Dialog 的使用
- [Android] Material 风格的 Dialog 的使用
- 使用DialogFragment代替Dialog定制各种样式
- Android中使用Dialog风格弹出框的Activity
- Android中使用Dialog风格弹出框的Activity
- Android中使用Dialog风格弹出框的Activity
- Android UI设计之<七>自定义Dialog,实现各种风格效果的对话框
- 自定义Dialog风格
- Dialog仿iphone风格
- 仿ios风格dialog
- Dialog风格的Activity
- 实现Dialog风格的Activity
- Java基础学习应用_数组常用方法与排序(一)
- 碎片
- Linux下C语言汉字逆置
- distinct去除重复值
- 介绍5款非常棒的移动自动化测试工具
- Dialog 各种风格使用
- Networkx_找出最大联通子图及联通子图规模排序
- Java使用getResource
- library - 程序库
- HTML+JS 代码块加载顺序
- 指针赋值的一些说明
- lsb - 最低有效位
- Splash页面的跳转逻辑
- msb - 最高有效位