Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create TimePickerDialog android

I want to create TimePickerDialog and theme is sample dialog.

but I follow this link

http://www.android-examples.com/create-timepickerdialog-to-select-time-in-12-hours-format-android/

result is not simple dialog

result is

enter image description here

I want

enter image description here

How to set this ?

and sorry My image is so large.

like image 613
ARR.s Avatar asked Aug 19 '17 05:08

ARR.s


People also ask

What is Timepickerdialog?

Android TimePicker is a user interface control for selecting the time in either 24-hour format or AM/PM mode. It is used to ensure that users pick the valid time for the day in our application.

How can you use time picker in Android application?

Android App Development for Beginners Android Time Picker allows you to select the time of day in either 24 hour or AM/PM mode. The time consists of hours, minutes and clock format. Android provides this functionality through TimePicker class.

What is DatePicker in Android?

Android DatePicker is a user interface control that is used to select the date by day, month, and year in the android application. DatePicker is used to ensure that the users will select a valid date.


2 Answers

I have made one method for old TimePickerDialog...i have same situation like you..this is working great for me..

Use below method

    public void showHourPicker() {
            final Calendar myCalender = Calendar.getInstance();
            int hour = myCalender.get(Calendar.HOUR_OF_DAY);
            int minute = myCalender.get(Calendar.MINUTE);


            TimePickerDialog.OnTimeSetListener myTimeListener = new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    if (view.isShown()) {
                        myCalender.set(Calendar.HOUR_OF_DAY, hourOfDay);
                        myCalender.set(Calendar.MINUTE, minute);

                    }
                }
            };
            TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar, myTimeListener, hour, minute, true);
            timePickerDialog.setTitle("Choose hour:");
  timePickerDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
            timePickerDialog.show();
        }

Hope this will help you...let me know if you need any help

like image 60
Lokesh Desai Avatar answered Sep 29 '22 21:09

Lokesh Desai


Try the below code. It looks almost similar to what image you have provided. Either use this

<TimePicker
    android:id="@+id/simpleTimePicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:timePickerMode="spinner"/>

enter image description here

or this.

 final Calendar calenderInstance = Calendar.getInstance();
    int hr = calenderInstance.get(Calendar.HOUR_OF_DAY);
    int min = calenderInstance.get(Calendar.MINUTE);
    TimePickerDialog.OnTimeSetListener onTimeListner = new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            if (view.isShown()) {
                calenderInstance.set(Calendar.HOUR_OF_DAY, hourOfDay);
                calenderInstance.set(Calendar.MINUTE, minute);
            }
        }
    };
    TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this,
            android.R.style.Theme_Holo_Light_Dialog_NoActionBar,
            onTimeListner, hr, min, true);
    timePickerDialog.setTitle("Set Time");
    Objects.requireNonNull(timePickerDialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
    timePickerDialog.show();
like image 41
Manish Singh Rana Avatar answered Sep 29 '22 21:09

Manish Singh Rana