I need to show only [00 , 15 , 30 ,45] in time picker i have searched but couldn't find anything , Does any one have idea how to achieve this ?
I need to show only [00 , 15 , 30 ,45] in time picker i have searched but couldn't find anything , Does any one have idea how to achieve this ?
Android Time Picker Does Not Provide setInterval() method to do that we need to work with MaterialDateTimepicker
implementation 'com.wdullaer:materialdatetimepicker:3.6.3'
its latest version was conflicting with some of my libraries that's why i used 3.6.3
Also those who are using NumberPicker to do that it doesn't work for me
Calendar now = Calendar.getInstance();
TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(mTimePickerListener,
now.get(Calendar.HOUR_OF_DAY),
now.get(Calendar.MINUTE),
false
);
timePickerDialog.setThemeDark(false);
timePickerDialog.setTitle("TimePicker Title");
timePickerDialog.setTimeInterval(1, 15, 30); // 15 Minutes Interval
//timePickerDialog.setTimeInterval(1, 30, 60); // 30 Minutes Interval
timePickerDialog.setAccentColor(Color.parseColor("#9C27B0"));
timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
Log.d("TimePicker", "Dialog was cancelled");
}
});
timePickerDialog.show(getFragmentManager(), "Timepickerdialog");
}
private TimePickerDialog.OnTimeSetListener mTimePickerListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second) {
}
};
you can create custom time picker by creating custom circle shape drawable and make it as a background of framelayout and to get the value of time listen to the click event of textviews
code : bg_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="2dp"/>
</shape>
layout_picker.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/bg_circle"
android:padding="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_gravity="center_horizontal|top"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15"
android:layout_gravity="center_vertical|end"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30"
android:layout_gravity="center_horizontal|bottom"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="45"
android:layout_gravity="center_vertical|start"
/>
</FrameLayout>
Hope it helps