更改 TimePicker 上的标题?
我正在尝试寻找一种解决方案来更改 TimePicker 对话框上的标题。现在它显示的是系统时间(例如“12:23 AM”),但我想将其更改为更具描述性的内容。有人有什么建议吗?
I'm trying to look for a solution to change the title on a TimePicker dialog. Right now it says whatever the system time is (ex. "12:23 AM") but I want to change this to something a little more descriptive. Does anyone have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
按要求。 :)
By request. :)
这个问题相当老了,但如果你搜索这个问题,它就会出现在谷歌结果中。所以,我想我会发布我的解决方案。
DatePicker
有setCustomTitle(View view)
,您可以在其中定义自己的视图(例如带有自定义文本的TextView
)以用作标题。更改值时不会更新此值。This question is rather old, but it shows up on Google results if you search this question. So, I thought I'll post my solution.
DatePicker
hassetCustomTitle(View view)
, where you can define your own view (e.g.TextView
with your custom text) to be used as a title. This one does not update when changing values.我不知道如何回复下面问题的评论,所以我用“回答”。
通过查看源代码: SourceCode
你可能会意识到 OnTimeChangedListener 是由 TimePickerDialog 实现的。
为了避免在调整时间时标题发生更改,您可以从 TimePickerDialog 派生并覆盖 public void onTimeChanged(TimePicker view, int hourOfDay, int 分钟);
注意,不要调用超级版本,否则会再次设置Title...
I dont know how to reply to the comments below question, so I use "Answer".
By looking into source code: SourceCode
You may realize that OnTimeChangedListener is implemented by TimePickerDialog.
To avoid title changed while adjusting time, you may derived from TimePickerDialog and override public void onTimeChanged(TimePicker view, int hourOfDay, int minute);
Notice, dont call super version, or it will setTitle again...