欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中常用的三個(gè)Dialog彈窗總結(jié)解析

 更新時(shí)間:2021年10月26日 10:55:18   作者:青素i  
自己雖然一直使用過dialog,但是一直都是復(fù)制、粘貼;不清楚dialog的具體用途,這次趁著有時(shí)間,總結(jié)一下具體用法,感興趣的朋友跟著小編來看看吧

ProgressDialog

    private  void showProgressDialog(){
        progressDialog = new ProgressDialog(DialogDemo.this);

        //設(shè)置提示信息
        progressDialog.setTitle("提示");
        progressDialog.setIcon(R.mipmap.touxiang0);

        progressDialog.setMessage("正在處理中");

        //是否用過返回鍵取消
        progressDialog.setCancelable(true);
        //碰觸彈框之外的地方取消
        progressDialog.setCanceledOnTouchOutside(true);


        //顯示
        progressDialog.show();
    }

在這里插入圖片描述

DatePickerDialog

 //日期
    private  void datePickerDialog(){
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
            DatePickerDialog datePickerDialog = new DatePickerDialog(DialogDemo.this);
            datePickerDialog.setOnDateSetListener(new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                    Toast.makeText(DialogDemo.this,year+"年"+(month+1)+"月"+dayOfMonth+"日",Toast.LENGTH_SHORT).show();
                }
            });
            datePickerDialog.show();
        }else {
            Toast.makeText(DialogDemo.this,"版本過低",Toast.LENGTH_SHORT).show();

        }
    }

在這里插入圖片描述

TimePickerDialog

    //時(shí)間
    private  void timePickerDialog(){
        //獲得日歷的實(shí)列
        Calendar calendar = Calendar.getInstance();

        //設(shè)置當(dāng)前時(shí)間
        calendar.setTimeInMillis(System.currentTimeMillis());

        //獲取時(shí)分

        int hour  = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);


        //第三、四個(gè)參數(shù)初始時(shí)分 第五個(gè)參數(shù)是否為24小時(shí)顯示
        TimePickerDialog time = new TimePickerDialog(DialogDemo.this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                Toast.makeText(DialogDemo.this,"Hour"+hourOfDay+"minute"+minute,Toast.LENGTH_SHORT).show();

            }
        },hour,minute,true);

        time.show();

    }

在這里插入圖片描述

布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".MainActivity"
    android:orientation="vertical"
    android:gravity="center_horizontal"

    >


    <Button
        android:id="@+id/btnProgress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="35dp"
        android:backgroundTint="#64D7E6"
        android:text="提示"
        android:textSize="35sp"

        />
    <Button
        android:id="@+id/btnDatePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="35dp"
        android:backgroundTint="#64D7E6"
        android:text="日期"
        android:textSize="35sp"

        />
    <Button
        android:id="@+id/btnTimePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="35dp"
        android:backgroundTint="#64D7E6"
        android:text="時(shí)間"
        android:textSize="35sp"
        />

</LinearLayout>

完整代碼

import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;

import java.util.Calendar;

public class DialogDemo extends AppCompatActivity {
    Button mBtnProgress,mBtnDatePicker,mBtnTimePicker;
    ProgressDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog_demo);
        initView();
        MyOnClick myOnClick = new MyOnClick();
        mBtnProgress.setOnClickListener(myOnClick);
        mBtnDatePicker.setOnClickListener(myOnClick);
        mBtnTimePicker.setOnClickListener(myOnClick);
    }

    private  void initView(){
        mBtnProgress = findViewById(R.id.btnProgress);
        mBtnDatePicker = findViewById(R.id.btnDatePicker);
        mBtnTimePicker = findViewById(R.id.btnTimePicker);
    }


    class MyOnClick implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch(v.getId()){
                case  R.id.btnProgress:
                    showProgressDialog();
                    break;
                case  R.id.btnDatePicker:
                    datePickerDialog();
                    break;
                case  R.id.btnTimePicker:
                    timePickerDialog();
                    break;
            }
        }
    }

    private  void showProgressDialog(){
        progressDialog = new ProgressDialog(DialogDemo.this);

        //設(shè)置提示信息
        progressDialog.setTitle("提示");
        progressDialog.setIcon(R.mipmap.touxiang0);

        progressDialog.setMessage("正在處理中");

        //是否用過返回鍵取消
        progressDialog.setCancelable(true);
        //碰觸彈框之外的地方取消
        progressDialog.setCanceledOnTouchOutside(true);


        //顯示
        progressDialog.show();
    }

    //日期
    private  void datePickerDialog(){
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
            DatePickerDialog datePickerDialog = new DatePickerDialog(DialogDemo.this);
            datePickerDialog.setOnDateSetListener(new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                    Toast.makeText(DialogDemo.this,year+"年"+(month+1)+"月"+dayOfMonth+"日",Toast.LENGTH_SHORT).show();
                }
            });
            datePickerDialog.show();
        }else {
            Toast.makeText(DialogDemo.this,"版本過低",Toast.LENGTH_SHORT).show();

        }
    }


    //時(shí)間
    private  void timePickerDialog(){
        //獲得日歷的實(shí)列
        Calendar calendar = Calendar.getInstance();

        //設(shè)置當(dāng)前時(shí)間
        calendar.setTimeInMillis(System.currentTimeMillis());

        //獲取時(shí)分

        int hour  = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);


        //第三、四個(gè)參數(shù)初始時(shí)分 第五個(gè)參數(shù)是否為24小時(shí)顯示
        TimePickerDialog time = new TimePickerDialog(DialogDemo.this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                Toast.makeText(DialogDemo.this,"Hour"+hourOfDay+"minute"+minute,Toast.LENGTH_SHORT).show();

            }
        },hour,minute,true);

        time.show();

    }

}

到此這篇關(guān)于Android中常用的三個(gè)Dialog彈窗總結(jié)解析的文章就介紹到這了,更多相關(guān)Android Dialog內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • android textview 顯示html方法解析

    android textview 顯示html方法解析

    現(xiàn)在網(wǎng)絡(luò)的繁盛時(shí)代,光文字是不能滿足人們的胃口的,圖片,flash,音頻,視頻就成為瀏覽網(wǎng)頁的主流顯示,在手機(jī)上也一樣,本文將詳細(xì)介紹此功能的實(shí)現(xiàn)方法
    2012-11-11
  • Android圖片處理工具類BitmapUtils

    Android圖片處理工具類BitmapUtils

    這篇文章主要為大家詳細(xì)介紹了Android圖片的處理工具類BitmapUtils,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android開發(fā)導(dǎo)入項(xiàng)目報(bào)錯(cuò)Ignoring InnerClasses attribute for an anonymous inner class的解決辦法

    Android開發(fā)導(dǎo)入項(xiàng)目報(bào)錯(cuò)Ignoring InnerClasses attribute for an anonym

    今天小編就為大家分享一篇關(guān)于Android開發(fā)導(dǎo)入項(xiàng)目報(bào)錯(cuò)Ignoring InnerClasses attribute for an anonymous inner class的解決辦法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • Android實(shí)現(xiàn)日夜間模式的深入理解

    Android實(shí)現(xiàn)日夜間模式的深入理解

    相信Android的日間/夜間模式切換相信大家在平時(shí)使用 APP 的過程中都遇到過,比如知乎、簡書中就有相關(guān)的模式切換。實(shí)現(xiàn)日間/夜間模式切換的方案也有許多種,趁著今天有空來講一下日間/夜間模式切換的幾種實(shí)現(xiàn)方案,也可以做一個(gè)橫向的對(duì)比來看看哪種方案最好。
    2016-09-09
  • Android中獲取控件寬高的4種方法集合

    Android中獲取控件寬高的4種方法集合

    下面小編就為大家分享一篇Android中獲取控件寬高的4種方法集合,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • Android Studio 3.6中使用視圖綁定替代 findViewById的方法

    Android Studio 3.6中使用視圖綁定替代 findViewById的方法

    從 Android Studio 3.6 開始,視圖綁定能夠通過生成綁定對(duì)象來替代 findViewById,從而可以幫您簡化代碼、移除 bug,并且從 findViewById 的模版代碼中解脫出來,今天通過本文給大家介紹使用視圖綁定替代 findViewById的方法,感興趣的朋友一起看看吧
    2020-03-03
  • Android實(shí)現(xiàn)在一個(gè)activity中添加多個(gè)listview的方法

    Android實(shí)現(xiàn)在一個(gè)activity中添加多個(gè)listview的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)在一個(gè)activity中添加多個(gè)listview的方法,分析了Activity中添加listview的原理與具體實(shí)現(xiàn)方法,需要的朋友可以參考下
    2016-08-08
  • android中實(shí)現(xiàn)完全退出程序方法(退出所有activity)

    android中實(shí)現(xiàn)完全退出程序方法(退出所有activity)

    這篇文章主要介紹了android中實(shí)現(xiàn)完全退出程序方法(退出所有activity),本文方法是博主個(gè)人使用的一個(gè)方法,據(jù)說效果非常好,需要的朋友可以參考下
    2015-05-05
  • Android MaterialCardView的使用介紹與示例

    Android MaterialCardView的使用介紹與示例

    MaterialCardView是一個(gè)基于Android支持庫中的CardView的可自定義組件。 MaterialCardView提供了CardView的所有功能,但增加了一些自定義屬性,使用起來更加方便實(shí)用
    2021-11-11
  • Android自定義輸入框提示功能

    Android自定義輸入框提示功能

    這篇文章主要為大家詳細(xì)介紹了Android自定義輸入框提示功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09

最新評(píng)論