Customize DatePicker. Android

后端 未结 2 616
难免孤独
难免孤独 2020-12-02 00:56

is there the way to customize a DatePicker? That is my Layout-Code.




        
2条回答
  •  情话喂你
    2020-12-02 01:38

    try this code

    put below code in xml file

    
    
    
        
    
            
    
                
    
                    
    
                    
    
                
            
    
        
    
        
    
            
    
                
            
        
    
    
    
    

    put below code in your activity or fragment

            final Dialog dialog = new Dialog(ConfirmBookingActivity.this, android.R.style.Theme_Holo_Dialog);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.dialog_date_picker);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    
            final DatePicker dp = (DatePicker) dialog.findViewById(R.id.dlgDatePicker);
            final TimePicker tp = (TimePicker) dialog.findViewById(R.id.timePicker1);
    
            LinearLayout linear_select_time = (LinearLayout) dialog.findViewById(R.id.linear_select_time);
    
            dp.setCalendarViewShown(false);
            Calendar cal = Calendar.getInstance();
            cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
            cal.add(Calendar.HOUR_OF_DAY, 1);
    
            dp.init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {
                @Override
                public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth) {
                    Log.d("Date", "Year=" + year + " Month=" + (month + 1) + " day=" + dayOfMonth);
                    calDay = dayOfMonth;
                    calMonth = month + 1;
                    calYear = year;
    
                    checkAndUpdateValue(tp);
                }
            });
    
    
            linear_select_time.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {
    
                });
    

提交回复
热议问题