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

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

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

ProgressDialog

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

        //設置提示信息
        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

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

        //設置當前時間
        calendar.setTimeInMillis(System.currentTimeMillis());

        //獲取時分

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


        //第三、四個參數(shù)初始時分 第五個參數(shù)是否為24小時顯示
        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="時間"
        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);

        //設置提示信息
        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();

        }
    }


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

        //設置當前時間
        calendar.setTimeInMillis(System.currentTimeMillis());

        //獲取時分

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


        //第三、四個參數(shù)初始時分 第五個參數(shù)是否為24小時顯示
        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();

    }

}

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

相關文章

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

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

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

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

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

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

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

    android實現(xiàn)簡單底部導航欄

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

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

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

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

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

    嵊泗县| 麻江县| 句容市| 余姚市| 灵山县| 珲春市| 家居| 桑植县| 噶尔县| 阳信县| 平乐县| 岳池县| 碌曲县| 泉州市| 海阳市| 梅河口市| 徐闻县| 屏山县| 清镇市| 四川省| 潢川县| 娄底市| 大埔县| 开封县| 牙克石市| 开原市| 通辽市| 都匀市| 佳木斯市| 葵青区| 北海市| 新巴尔虎左旗| 襄城县| 成安县| 永平县| 谷城县| 吴桥县| 浦县| 页游| 岳阳县| 靖西县|