DataPicker looks like old design on new API's as well

前端 未结 4 985
一整个雨季
一整个雨季 2021-01-12 11:16

So the problem is very simple:

I have integrated a DatePicker in my application. Not as a DialogDatePicker but as a View component (more pr

4条回答
  •  时光说笑
    2021-01-12 11:56

    Here is a snippet for calling device's default Date And Time Picker

    date_time_layout.xml

     
        
    
            
    
                 
                
    
                
                
    
                
    
                    

    Put this method in your class and call it using showDateAndTimePicker();

    private void showDateAndTimePicker() {
            final Dialog dialog = new Dialog(this,
                    android.R.style.Theme_DeviceDefault_Dialog);
    
            dialog.setContentView(R.layout.date_time_layout);
            dialog.setCancelable(false);
            dialog.setTitle("Select Date and Time");
            Button set = (Button) dialog.findViewById(R.id.dialogSet);
            Button cancel = (Button) dialog.findViewById(R.id.dialogCancel);
            final DatePicker dtp = (DatePicker) dialog
                    .findViewById(R.id.datePicker1);
            final TimePicker tp = (TimePicker) dialog
                    .findViewById(R.id.timePicker1);
            set.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // Handle Set button
                    dialog.dismiss();
    
                }
            });
            cancel.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                     //Handle Cancel button
                    dialog.dismiss();
                }
                });
                dialog.show();
            }
    

提交回复
热议问题