• 一手遮天 Android


    项目地址 https://github.com/webabcd/AndroidDemo
    作者 webabcd

    一手遮天 Android - view(弹出类): TimePickerDialog 基础

    示例如下:

    /view/flyout/TimePickerDialogDemo1.java

    /**
     * TimePickerDialog - 时间选择对话框
     *
     * 注1:TimePickerDialog 继承自 AlertDialog
     * 注2:实际项目中建议使用第三方的时间选择控件
     */
    
    package com.webabcd.androiddemo.view.flyout;
    
    import android.app.TimePickerDialog;
    import androidx.appcompat.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TimePicker;
    import android.widget.Toast;
    
    import com.webabcd.androiddemo.R;
    
    import java.util.Calendar;
    
    public class TimePickerDialogDemo1 extends AppCompatActivity {
    
        private Button mButton1;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_view_flyout_timepickerdialogdemo1);
    
            mButton1 = findViewById(R.id.button1);
    
            sample();
        }
    
        private void sample() {
            mButton1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Calendar calendar = Calendar.getInstance();
                    TimePickerDialog timePickerDialog = new TimePickerDialog(TimePickerDialogDemo1.this, new TimePickerDialog.OnTimeSetListener() {
                        @Override
                        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                            // 获取用户选择的时间
                            Toast.makeText(getApplicationContext(), String.format("%d:%d", hourOfDay, minute), Toast.LENGTH_SHORT).show();
                        }
                    },
                            calendar.get(Calendar.HOUR_OF_DAY),
                            calendar.get(Calendar.MINUTE), true);
    
                    timePickerDialog.show();
                }
            });
        }
    }
    
    

    /layout/activity_view_flyout_timepickerdialogdemo1.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAllCaps="false"
            android:text="弹出时间选择对话框" />
    
    </LinearLayout>
    
    

    项目地址 https://github.com/webabcd/AndroidDemo
    作者 webabcd

  • 相关阅读:
    [bzoj1568]李超线段树模板题(标志永久化)
    [tyvj1860]后缀数组
    [poj3264]rmq算法学习(ST表)
    LintCode-82.落单的数
    LintCode-53.翻转字符串
    LintCode-56.两数之和
    LintCode-379.将数组重新排序以构造最小值
    LintCode-5.第k大元素
    LintCode-3.统计数字
    LintCode-4.丑数 II
  • 原文地址:https://www.cnblogs.com/webabcd/p/android_view_flyout_TimePickerDialogDemo1.html
Copyright © 2020-2023  润新知