TimePicker with Spinners?

不羁岁月 提交于 2021-02-18 12:15:07

问题


I'm trying to build a TimePickerDialog but unfortunately the Time Picker that comes up is extremely cumbersome to Use :

Is there any way to build a timepicker like the old ones that Android use to have like below :

My code is as follows :

    ButtonTime.Click += delegate
    {
        ShowTimePickerDialog();
    };

    void ShowTimePickerDialog()
    {
        var dialog = new TimePickerDialogFragment(this, hour, minute, this);

        dialog.Show(FragmentManager, null);
    }

回答1:


I would say use the Holo theme. I refer to following link on stackoverflow which you might find usefull.




回答2:


adding new xml style

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="SpinnerTimePicker" parent="android:Widget.Material.Light.TimePicker">
    <item name="android:timePickerMode">spinner</item>
  </style>

  <style name="ClockTimePicker" parent="android:Widget.Material.Light.TimePicker">
    <item name="android:timePickerMode">clock</item>
  </style>
</resources>

than set the timepicker style to SpinnerTimePicker in MainTheme

 <item name="android:timePickerStyle">@style/SpinnerTimePicker</item>



回答3:


android:timePickerMode Defines the look of the widget. Prior to the L release, the only choice was spinner. As of L, with the Material theme selected, the default layout is clock, but this attribute can be used to force spinner to be used instead.

Must be one of the following constant values.

Constant Value Description clock 2 Time picker with clock face to select the time. spinner 1 Time picker with spinner controls to select the time.

from Documentaion

https://developer.android.com/reference/android/widget/TimePicker.html#attr_android:timePickerMode



来源:https://stackoverflow.com/questions/34596666/timepicker-with-spinners

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