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);
}
}