最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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 RecyclerView點(diǎn)擊展開、折疊效果的實(shí)現(xiàn)代碼

    一文搞懂Android RecyclerView點(diǎn)擊展開、折疊效果的實(shí)現(xiàn)代碼

    雖然在日常開發(fā)中已經(jīng)多次接觸過RecycleView,但也只是用到其最基本的功能,并沒有深入研究其他內(nèi)容。接下來將抽出時(shí)間去了解RecycleView的相關(guān)內(nèi)容,這篇文章主要是介紹Android RecyclerView點(diǎn)擊展開、折疊效果的實(shí)現(xiàn)方式,一起看看吧
    2021-06-06
  • Android中Fragment 真正的完全解析(上)

    Android中Fragment 真正的完全解析(上)

    本篇文章主要介紹了Android中Fragment完全解析,具有一定的參考價(jià)值,有需要的可以了解一下。
    2016-11-11
  • Android實(shí)現(xiàn)搖一搖功能

    Android實(shí)現(xiàn)搖一搖功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)搖一搖功能的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • android實(shí)現(xiàn)簡單底部導(dǎo)航欄

    android實(shí)現(xiàn)簡單底部導(dǎo)航欄

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)簡單底部導(dǎo)航欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • Android編程基于自定義控件實(shí)現(xiàn)時(shí)鐘功能的方法

    Android編程基于自定義控件實(shí)現(xiàn)時(shí)鐘功能的方法

    這篇文章主要介紹了Android編程基于自定義控件實(shí)現(xiàn)時(shí)鐘功能的方法,結(jié)合實(shí)例形式詳細(xì)分析了Android自定義控件的定義及時(shí)鐘功能相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2018-03-03
  • Android使用控件ImageView加載圖片的方法

    Android使用控件ImageView加載圖片的方法

    這篇文章主要為大家詳細(xì)介紹了Android使用ImageView加載圖片的方法,Android ImageView如何加載網(wǎng)絡(luò)圖片資源,感興趣的小伙伴們可以參考一下
    2016-05-05
  • 最新評(píng)論

    岑巩县| 磐石市| 岳西县| 凤庆县| 阿克| 永平县| 青铜峡市| 靖宇县| 响水县| 敦煌市| 昌图县| 淳安县| 桦川县| 鸡泽县| 大关县| 日土县| 民勤县| 新闻| 朝阳县| 屏东市| 铁力市| 基隆市| 岐山县| 孝感市| 扶沟县| 杭锦后旗| 顺义区| 泗水县| 铜鼓县| 家居| 鹿邑县| 嘉祥县| 永寿县| 枞阳县| 青川县| 丹凤县| 桐乡市| 宿松县| 蓝山县| 韶山市| 保定市|