zoukankan      html  css  js  c++  java
  • 一手遮天 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

  • 相关阅读:
    Linux配置环境变量
    入坑CV DL一些基础技能学习
    (Linux)初探cmake .和make命令
    Django rest framework 之分页
    Django rest framework 之版本
    通用权限框架
    堡垒机
    kingadmin
    CRM 客户关系管理系统
    Torando 入门
  • 原文地址:https://www.cnblogs.com/webabcd/p/android_view_flyout_TimePickerDialogDemo1.html
Copyright © 2011-2022 走看看