区块链技术博客
www.b2bchain.cn

Android height 1 day1Dialog对话框

这篇文章主要介绍了Android height 1 day1Dialog对话框的讲解,通过具体代码实例进行17574 讲解,并且分析了Android height 1 day1Dialog对话框的详细步骤与相关技巧,需要的朋友可以参考下https://www.b2bchain.cn/?p=17574

本文实例讲述了2、树莓派设置连接WiFi,开启VNC等等的讲解。分享给大家供大家参考文章查询地址https://www.b2bchain.cn/7039.html。具体如下:

Dialog对话框

  • 常用的对话框
    • 1.普通对话框
    • 2.单选对话框
    • 3.多选对话框
    • 4.自定义对话框(******)
    • 5.水平进度条对话框
    • 6.圆形进度条对话框
    • 7.日期选择对话框
    • 8.时间选择对话框
  • 自定义对话框

常用的对话框

对话框
普通 AlertDialog.Builder()
单选 AlertDialog.Builder()
多选 AlertDialog.Builder()
日期 DatePickerDialog
时间 TimePickerDialog
水平 ProgressDialog
圆圈 ProgressDialog
自定义 AlertDialog.Builder()

1.普通对话框

Android height 1 day1Dialog对话框

 b11.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {             //TODO 1:构建者                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 			//TODO 2:设置属性                builder.setTitle("标题");//设置标题                builder.setMessage("内容");//设置内容                builder.setIcon(R.mipmap.ic_launcher);//设置图标 				//设置确定按钮                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialog, int which) {                        Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_SHORT).show();                    }                });                 //设置取消按钮                 builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {                     @Override                     public void onClick(DialogInterface dialog, int which) {                         Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();                     }                 });                        			 //TODO 3:使用建造者创建对话框                 AlertDialog alertDialog = builder.create();                  //TODO 4:显示                 alertDialog.show();             }         }); 

2.单选对话框

Android height 1 day1Dialog对话框

b1.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {             //TODO 1:构建者                 AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 				//TODO 设置单选列表 				//TODO  参数一 列表  参数二 默认选中下表  参数三 事件监听                 final String[] strings = new String[]{"男", "女", "外星人"};                 builder.setSingleChoiceItems(strings, 0, new DialogInterface.OnClickListener() {                     @Override                     public void onClick(DialogInterface dialog, int which) {                         Toast.makeText(MainActivity.this, "" + strings[which], Toast.LENGTH_SHORT).show();                     }                 });                 //TODO 3:使用建造者创建对话框                 AlertDialog alertDialog = builder.create();                  //TODO 4:显示                 alertDialog.show();             }         }); 

3.多选对话框

Android height 1 day1Dialog对话框

b2.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {             //TODO 1:构建着                 AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);  				//TODO 设置多选列表        			 //TODO  参数一 列表  参数二 默认选中下表  参数三 事件监听                 final String[] strings = new String[]{"男", "女", "外星人"};                 final boolean[] booleans = new boolean[]{false, false, false};                 builder.setMultiChoiceItems(strings, booleans, new DialogInterface.OnMultiChoiceClickListener() {                     @Override                     public void onClick(DialogInterface dialog, int which, boolean isChecked) {                         if (booleans[which]) {                             Toast.makeText(MainActivity.this, "" + strings[which], Toast.LENGTH_SHORT).show();                         } else {                             Toast.makeText(MainActivity.this, "" + strings[which] + "取消了", Toast.LENGTH_SHORT).show();                         }                     }                 });                  //TODO 3:使用建造者创建对话框                 AlertDialog alertDialog = builder.create();                  //TODO 4:显示                 alertDialog.show();             }         }); 

4.自定义对话框(******)

Android height 1 day1Dialog对话框

 b3.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {              //TODO 1:构建着                 AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 			 //TODO 2:视图填充器                 View inflate = LayoutInflater.from(MainActivity.this).inflate(R.layout.leio_layout, null);                 builder.setView(inflate);  				  				 //TODO 3:使用建造者创建对话框                 final AlertDialog alertDialog = builder.create();  				//获取到id,点击事件                 ImageView imageView = inflate.findViewById(R.id.img);                 imageView.setOnClickListener(new View.OnClickListener() {                     @Override                     public void onClick(View v) {                     //关闭                         alertDialog.dismiss();                     }                 }); 				//TODO 4:显示                 alertDialog.show();             }         }); 
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="match_parent"     android:gravity="center"     android:layout_height="match_parent">      <ImageView         android:id="@+id/img"         android:layout_width="300dp"         android:layout_height="500dp"         android:src="@mipmap/leio"         ></ImageView> </LinearLayout> 

5.水平进度条对话框

Android height 1 day1Dialog对话框

 b4.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {             //进度条对话框                 final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); 				//最大值                 progressDialog.setMax(100);                 //精准进度条                 progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 				//定时器                 Timer timer = new Timer();                 timer.schedule(new TimerTask() {                     int i = 0;                     @Override                     public void run() {                         i += 10;                         progressDialog.setProgress(i);                         if (i>=progressDialog.getMax()){                             progressDialog.dismiss();                         }                     }                 },0,1000);  				//显示                 progressDialog.show();             }         }); 

6.圆形进度条对话框

Android height 1 day1Dialog对话框

 b4.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {            	                 final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);                  progressDialog.setMax(100);                                   progressDialog.show();             }         }); 

7.日期选择对话框

Android height 1 day1Dialog对话框

b5.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {            /**          *          *          * @param context 上下文          * @param listener 监听器          * @param year 默认的年          * @param month 默认的月          * @param dayOfMonth 默认的日          */                 Calendar instance = Calendar.getInstance();//日历对象                  DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {                     @Override                     public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {                      }                 },instance.get(Calendar.YEAR),instance.get(Calendar.MONTH),instance.get(Calendar.DAY_OF_MONTH));                  datePickerDialog.show();             }         }); 

8.时间选择对话框

Android height 1 day1Dialog对话框

 b6.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {             /**          * @param context 上下文          * @param listener 监听器          * @param hourOfDay 默认的时          * @param minute 默认的分钟          * @param is24HourView 是否采用24时禁止          */                 Calendar instance = Calendar.getInstance();//日历对象                  TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {                     @Override                     public void onTimeSet(TimePicker view, int hourOfDay, int minute) {                      }                 },instance.get(Calendar.HOUR),instance.get(Calendar.MINUTE),true);                 timePickerDialog.show();             }         }); 

自定义对话框

Android height 1 day1Dialog对话框

 b7.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 MyDialog myDialog = new MyDialog(MainActivity.this);                  myDialog.setYesClick(new MyDialog.YesClick() {                     @Override                     public void YesClick() {                         Toast.makeText(MainActivity.this, "确认", Toast.LENGTH_SHORT).show();                     }                 });                 myDialog.setNoClick(new MyDialog.NoClick() {                     @Override                     public void onClick() {                      }                 });                  myDialog.show();             }         }); 
package com.example.day1lx01;  import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast;  import androidx.annotation.NonNull;  public class MyDialog extends Dialog {     private TextView title;     private TextView message;     private Button no;     private Button yes;      public MyDialog(@NonNull Context context) {         super(context);     }      public interface YesClick{         void YesClick();     }     private YesClick yesClick;      public void setYesClick(YesClick yesClick) {         this.yesClick = yesClick;     }      public interface NoClick{         void onClick();     }     private NoClick noClick;     public void setNoClick(NoClick noClick) {         this.noClick = noClick;     }      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_my_dialog);         initView();     }      private void initView() {         title = (TextView) findViewById(R.id.title);         message = (TextView) findViewById(R.id.message);         no = (Button) findViewById(R.id.no);         yes = (Button) findViewById(R.id.yes);          yes.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 yesClick.YesClick();                 dismiss();             }         });          no.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 noClick.onClick();                 Toast.makeText(getContext(), "取消", Toast.LENGTH_SHORT).show();                 dismiss();             }         });     } }  
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".MyDialog">      <LinearLayout         android:layout_width="300dp"         android:layout_height="wrap_content"         android:layout_centerInParent="true"         android:orientation="vertical">         <TextView             android:id="@+id/title"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:layout_marginTop="10dp"             android:text="警告"              android:textColor="#38ADFF"             android:textSize="16sp"/>         <TextView             android:id="@+id/message"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_margin="20dp"             android:layout_gravity="center"             android:text="保护视力,少玩手机"/>         <View             android:layout_width="match_parent"             android:layout_height="1px"             android:layout_marginTop="15dp"             android:background="#E4E4E4"/>         <LinearLayout             android:layout_width="match_parent"             android:layout_height="40dp"             android:orientation="horizontal">             <Button                 android:id="@+id/no"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_weight="1"                 android:layout_marginLeft="10dp"                 android:background="@null"                 android:gravity="center"                 android:lines="1"                 android:text="取消"                 android:textColor="#7D7D7D"                 android:textSize="16sp"/>             <View                 android:layout_width="1px"                 android:layout_height="match_parent"                 android:background="#E4E4E4"/>             <Button                 android:id="@+id/yes"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_weight="1"                 android:layout_marginRight="10dp"                 android:background="@null"                 android:gravity="center"                 android:lines="1"                 android:text="确定"                 android:textColor="#38ADFF"                 android:textSize="16sp"/>         </LinearLayout>     </LinearLayout> </RelativeLayout> 

本文转自互联网,侵权联系删除Android height 1 day1Dialog对话框

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » Android height 1 day1Dialog对话框
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们