我有一个非常有用的应用,直到我将手机升级到Android 7
问题是我需要选择器只选择月份和年份(没有日期)
在旧的Android版本上,我有这个:
有没有办法将应用中的选择器设置为旧样式,还是只选择月份和年份的其他想法?
我在构造函数上尝试了主题样式参数,如下所示:
final Calendar c = Calendar.getInstance();
DatePickerDialog dpd = new DatePickerDialog(context, android.R.style.Theme_Holo_Dialog ,listener,
c.get(Calendar.YEAR),
c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH));
但它也没有帮助,我得到相同的结果(不同的主题):
为什么在没有我作为开发人员将其设置为新选择器的情况下,它首先会发生变化?
您可以在此处查看清洁代码:
GitHub DatePicker test
答案 0 :(得分:1)
试试这个: -
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_LIGHT,this,year,month,day);
datepickerdialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
// arg1 = year
// arg2 = month
// arg3 = day
}
};
答案 1 :(得分:0)
创建 renderBalanceAndName() {
const balance = this.context.account.getIn(['balance', 'total']);
const firstName = this.context.account.getIn(['accountDetails', 'data', 'firstName']);
while (firstName !== null) {
return (
<Spinner size={theme.fontSize.alpha}/>,
<span>{firstName} {" "} — {" "}
<Money value={balance} /></span>
);
}
return (
<Spinner size={theme.fontSize.alpha}/>
)
},
renderAccountDetails() {
const balancePending = this.context.account.getIn(['balance', 'pending']);
return (
<div style={{display: 'inline-block'}}>
<span style={styles.balance} className="qa-nav-balance-and-name">
{balancePending && <Spinner size={theme.fontSize.alpha}/>}
{!balancePending && this.renderBalanceAndName(this.context.account)}
</span>
</div>
);
},
时,您可以为其设置旧样式
DatePickerDialog
答案 2 :(得分:0)
private DatePickerDialog createDialogWithoutDateField() {
DatePickerDialog onlyMonthdAndYearPicker = new DatePickerDialog(this, null, 2014, 1, 24);
try {
java.lang.reflect.Field[] datePickerDialogFields = dpd.getClass().getDeclaredFields();
for (java.lang.reflect.Field datePickerDialogField : datePickerDialogFields) {
if (datePickerDialogField.getName().equals("mDatePicker")) {
datePickerDialogField.setAccessible(true);
DatePicker datePicker = (DatePicker) datePickerDialogField.get(onlyMonthdAndYearPicker);
java.lang.reflect.Field[] datePickerFields = datePickerDialogField.getType().getDeclaredFields();
for (java.lang.reflect.Field datePickerField : datePickerFields) {
Log.i("test", datePickerField.getName());
if ("mDaySpinner".equals(datePickerField.getName())) {
datePickerField.setAccessible(true);
Object dayPicker = datePickerField.get(datePicker);
((View) dayPicker).setVisibility(View.GONE);
}
}
}
}
}
catch (Exception ex) {
}
return onlyMonthdAndYearPicker;
}
并调用此方法
createDialogWithoutDateField().show();