Skip to content Skip to sidebar Skip to footer

Android Timepicker Not Displayed Well On Landscape Mode

I'm currently building an app targeting API 23, with a minimum API 16. I'm facing an issue where a TimePicker is displayed within an AlertDialog. The display looks fine on Portrait

Solution 1:

You have to remove set title from time picker dialogue after that you will see time picker dialogue in Nexus 5. This issue is posted on google forum see below link :

https://code.google.com/p/android/issues/detail?id=201766

 TimePickerDialog mTimePicker;

        String[] time = txtTimeWriteOut.getText().toString().trim().split(":");
        inthour= Integer.parseInt(time[0]);
        intminute= Integer.parseInt(time[1]);

        mTimePicker = newTimePickerDialog(this, newTimePickerDialog.OnTimeSetListener() {
            @OverridepublicvoidonTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {

                txtTimeWriteOut.setText(TimeUtils.getDoubleDigits(selectedHour) + ":" + TimeUtils.getDoubleDigits(selectedMinute));

                passTimeOut = currentDate + TimeUtils.getDoubleDigits(selectedHour) + TimeUtils.getDoubleDigits(selectedMinute) + "00";

            }
        }, hour, minute, true);

//        mTimePicker.setTitle("Select Time");
        mTimePicker.show();

Solution 2:

I have this issue. This help for me:

timePicker.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

Solution 3:

1. If you DON'T care about loosing the title on your dialog:

If you are strictly following the official documentation on Pickers, here is what you have to do in your onCreateDialog() method:

Instead of creating new instance of TimePickerDialog and returning it straight away, call setTitle(null) on it before you return it, like so:

@Overridepublic Dialog onCreateDialog(Bundle savedInstanceState) {

    /* ... */DialogdialogFragment=newTimePickerDialog(/* ... */);
    dialogFragment.setTitle(null);
    return dialogFragment;
}

I would like to note, that the problem was not occurring on Android 5.0.2 (Lollipop). The dialog was without the title by default.

The problem occurred on Android 6.0 device. It displayed the very same dialog with a title.

2. If having the title on the dialog is a must for you:

You should read the source code for TimePickerDialog. No other way around. I didn't go full rage-mode on the source code, since I had the luxury of just setting it to null.

I believe you can find a private method setupTitle() of the package-private class AlertController very interesting. AlertControler is used in AlertDialog business logic.

Post a Comment for "Android Timepicker Not Displayed Well On Landscape Mode"