是否可以从 TimePicker 中删除 AM/PM 按钮?

发布于 2024-10-01 18:43:06 字数 172 浏览 1 评论 0原文

我想使用 TimePicker 显示24 小时时钟而不是12 小时,并且我不需要 AM/PM 按钮,只是想显示 24 小时时钟。

这可能吗?

我使用了 setIs24HourView(true) 但它不起作用。

建议我 如何显示 24 小时时钟?

I want to show 24 hours clock instead 12 hours using TimePicker,and I dont need the AM/PM buton, Simply want to show 24 hours clock.

Is this possible?

I used setIs24HourView(true) but it is is not working.

Suggest me How can I show 24 hours clock?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

在风中等你 2024-10-08 18:43:06

您是否尝试过设置 setIs24HourView ?

如果您只是需要以其他非正常方式使用 NumberPicker 小部件:

Android 中有一个 NumberPicker 小部件,但它是一个私有 API。 此人提取了代码,以便您可以将其放入任何项目中。

以下是我如何将其用于税率的示例:

alt text

Have you tried setting setIs24HourView?

If you just need use the NumberPicker widget in other abnormal ways:

There is a NumberPicker widget in Android, but it is a private API. This guy pulled out the code such that you can drop it into any project.

Here is an example of how I used it for tax rates:

alt text

深者入戏 2024-10-08 18:43:06

我遇到了同样的问题,但通过在活动的 onCreate 调用中执行 setIs24HourView 解决了它。

I've experienced the same problem but solved it by doing the setIs24HourView in the onCreate call for the activity..

走过海棠暮 2024-10-08 18:43:06

您必须调用 setIs24HourView 函数并为此发送 true。
当时间选择器处于 24 模式时 AM/PM 将消失。

TimePicker tpHourMin = (TimePicker) findViewById(R.id.timePicker);
tpHourMin.setIs24HourView(true);

You must call setIs24HourView function and send true for that.
when time picker are in 24 mode AM/PM will be disappear.

TimePicker tpHourMin = (TimePicker) findViewById(R.id.timePicker);
tpHourMin.setIs24HourView(true);
私野 2024-10-08 18:43:06

您可以覆盖

public void onTimeChanged (TimePicker view, int hourOfDay, int minute) 
method of TimePickerDialog to completely remove AM/PM:

class MyTimePickerDialog extends TimePickerDialog {
    MyTimePickerDialog(Context context, TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) {
        super(context, callBack, hourOfDay, minute, is24HourView);
    }
@Override
public void onTimeChanged (TimePicker view, int hourOfDay, int minute) {
    // to prevent the dialog from changing the title which by default contains AM/PM
}
}

这里是如何使用它

MyTimePickerDialog dialog = new MyTimePickerDialog(getActivity(), this, hour, minute, 
                        true /*DateFormat.is24HourFormat(getActivity())*/);
dialog.setTitle("Set Time");

You can overrite the

public void onTimeChanged (TimePicker view, int hourOfDay, int minute) 
method of TimePickerDialog to completely remove AM/PM:

class MyTimePickerDialog extends TimePickerDialog {
    MyTimePickerDialog(Context context, TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) {
        super(context, callBack, hourOfDay, minute, is24HourView);
    }
@Override
public void onTimeChanged (TimePicker view, int hourOfDay, int minute) {
    // to prevent the dialog from changing the title which by default contains AM/PM
}
}

Here is how to use it

MyTimePickerDialog dialog = new MyTimePickerDialog(getActivity(), this, hour, minute, 
                        true /*DateFormat.is24HourFormat(getActivity())*/);
dialog.setTitle("Set Time");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文