How to make the TimePicker smaller

前端 未结 2 769
温柔的废话
温柔的废话 2020-12-09 11:59

Is it possible to make the default TimePicker smaller in the activity xml? I have searched this but so far only found out how to create a custom time picker which I do not w

2条回答
  •  無奈伤痛
    2020-12-09 12:41

    You cannot change the size of TimePicker, how ever you can do one thing. You can make TimePicker as a Dialog.

    Checkout the following code:

    Button setTime;
    setTime = (Button)findViewById(R.id.button1);
    setTime.setOnClickListener(this);
    
    public void onClick(View v) 
    {
        TimePickerDialog tp1 = new TimePickerDialog(this, this, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true);
        tp1.show();
    }
    
    public void onTimeSet(TimePicker view, int hourOfDay, int minute)
    {
        cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
        cal.set(Calendar.MINUTE, minute);
        //rest of the code
    }
    

提交回复
热议问题