Reputation: 3537
Is there any way to remove the AM/PM
in a Time Picker Widget
?
I have this function in my application but its purpose is to select only Hour and Minutes not including AM/PM, I tried to setIs24HourView(true)
but it makes the time 24hours, I only want 12 hours.
Upvotes: 2
Views: 3468
Reputation: 39191
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) {
amPmLayout.setVisibility(View.GONE);
}
}
Upvotes: 5