Seynal Seynal - 1 year ago 132
Android Question

Removing AM/PM in Android Time picker Widget

Is there any way to remove the

in a
Time Picker Widget

enter image description here

I have this function in my application but its purpose is to select only Hour and Minutes not including AM/PM, I tried to
but it makes the time 24hours, I only want 12 hours.

Answer Source

It seems there is no public method in TimePicker to directly hide or show the AM/PM chooser. However, a look at the source code will give us the name of the resource ID for that View, which we can get with the system Resources. Then it's simply a matter of finding the View, and setting its visibility to GONE.

private void hideAmPmLayout(TimePicker picker) {
    final int id = Resources.getSystem().getIdentifier("ampm_layout", "id", "android");
    final View amPmLayout = picker.findViewById(id);
    if(amPmLayout != null) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download