gpt4 book ai didi

android - TimePickerDialog 取消和确定按钮未显示

转载 作者:太空宇宙 更新时间:2023-11-03 12:45:10 27 4
gpt4 key购买 nike

我有一个扩展 DialogFragment 的类,在这个类中我使用了 TimePickerDialog

时间选择器工作,但问题是有时 CANCELOK 按钮不显示,如下图所示。

按钮有效但不可见。

这是用于时间选择器的代码。

public static class TimePickerFragment extends android.support.v4.app.DialogFragment
implements TimePickerDialog.OnTimeSetListener {

// String used to set both Start and end times
String startEndTime;


@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);

Bundle b = getArguments();

if (b != null) {
startEndTime = b.getString("startEndTime");
}


// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}


public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

// Do something with the time chosen by the user
switch (startEndTime) {

case "startTime":

break;

case "endTime":

break;

default:

break;

}

}
}


public void showTimePickerDialog(String startEndTime) {

TimePickerFragment timePickerFragment = new TimePickerFragment();

Bundle b = new Bundle();

b.putString("startEndTime", startEndTime);

timePickerFragment.setArguments(b);

timePickerFragment.show(context.getSupportFragmentManager(), "timePicker");

}

enter image description here enter image description here

最佳答案

我解决了这个问题,我认为由于某些原因按钮的字体颜色有时显示为白色,不知道为什么。

为了解决这个问题,我向 TimePickerDialog 添加了一个对话框主题来设置按钮文本颜色。

这是我添加到 styles.xml 的 xml 代码

<style name="MyTimePickerDialogTheme" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="android:textColor">@color/colorAccent</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

这是我更改的代码。

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);

Bundle b = getArguments();

if (b != null) {
startEndTime = b.getString("startEndTime");
}


// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), R.style.MyTimePickerDialogTheme, this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}

关于android - TimePickerDialog 取消和确定按钮未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48000426/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com