Removing AM/PM in Android Time picker Widget

百般思念 提交于 2019-12-12 21:14:57

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/39071104/removing-am-pm-in-android-time-picker-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!