我正在设置CustomTimePicker,并且需要使用其他任何时钟图像或图标来更改时间选择器的时钟图像。
<TimePicker
android:layout_width="match_parent"
android:layout_height="match_parent"
android:timePickerMode="clock"
/>
“是他们的任何样式,还是可以与我的图标或图片交换图标的其他方式?”
答案 0 :(得分:0)
在时间选择器中,有一个重要的属性:
android:timePickerMode="spinner" or "clock"
以及使用背景色设置主题:
android:theme="@style/TimePickerTheme"
答案 1 :(得分:0)
validTillTime.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
KeyboardUtility.hideKeyboard(CreatePassActivityTwo.this);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
TimePickerUtility.getTime(CreatePassActivityTwo.this).show();
validFrom = 0;
return false;
}
return true;
validTillTime是此处的EditText。
public class TimePickerUtility {
public static TimePickerDialog getTime(final Context context) {
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
TimePickerDialog.OnTimeSetListener timeSetListener =
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
TimePickerListener timePickerListener = (TimePickerListener) context;
timePickerListener.onReceiveTime(hourOfDay, minute);
}
};
return new TimePickerDialog(context,
R.style.TimePickerTheme, timeSetListener, hour, minute, false);
}
public interface TimePickerListener {
void onReceiveTime(int hour, int minute);
}
在活动中实现TimePickerListener。
@Override
public void onReceiveTime(int hour, int minute) {
if (validFrom == 1) {
validFromTime.setText(TimeFormatterUtility.getFormattedTime(hour, minute));
} else {
validTillTime.setText(TimeFormatterUtility.getFormattedTime(hour, minute));
}
}
<style name="TimePickerTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/buttonColor</item>
<item name="android:timePickerStyle">@style/TimePickerStyle</item>
</style>
<style name="TimePickerStyle" parent="@android:style/Widget.Material.Light.TimePicker">
<item name="android:headerBackground">@color/colorPrimary</item>
<item name="android:timePickerMode">spinner</item>
<item name="android:headerTimeTextAppearance">@color/colorPrimaryDark</item>
</style>