ria*_*nor 2 android datepicker
我试图DatePicker在另一个活动的顶部显示一个对话框,正在发生的是它以某种方式继承了它的颜色。
我希望它具有绿色的标头和白色的背景,

这是样式的节选
<style name="DatePickerDialog" parent="@android:style/Theme.Holo.Light">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="colorAccent">@color/primary</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这段代码用来弹出 DatePicker
DatePickerDialog datepicker = new DatePickerDialog(this, R.style.DatePickerDialog, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
TextView newdate = (TextView) findViewById(R.id.newdate);
Date date = getDate(year, monthOfYear, dayOfMonth);
DateFormat dateformat = new SimpleDateFormat(getResources().getString(R.string.date_format_full));
newdate.setText(dateformat.format(date));
}
}, newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
datepicker.show();
Run Code Online (Sandbox Code Playgroud)

如果我在样式中指定白色背景, 
<item name="android:background">@color/app_background</item>
Run Code Online (Sandbox Code Playgroud)
我尝试过的最后一件事是AlertDialog.THEME_DEVICE_DEFAULT_DARK用作DatePicker主题
DatePickerDialog datepicker = new DatePickerDialog(this,
AlertDialog.THEME_DEVICE_DEFAULT_DARK, new
DatePickerDialog.OnDateSetListener()
Run Code Online (Sandbox Code Playgroud)

这是我从中打开对话框的活动的样式
<style name="UserDialog" parent="android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:background">@color/primary</item>
<item name="android:textColor">@color/dialog_text</item>
<item name="colorPrimary">@color/app_background</item>
<item name="android:windowTitleStyle">@style/NewDialogTitle</item>
</style>
<style name="NewDialogTitle" parent="@android:style/TextAppearance.DialogWindowTitle">
<item name="android:gravity">center_horizontal</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我正在使用的颜色
<color name="primary">#4CAF50</color>
<color name="app_background">#FFFFFF</color>
Run Code Online (Sandbox Code Playgroud)
有谁知道如何完成它?我将不胜感激。我尝试遵循此答案,但没有运气
此代码对我有用,请尝试...
styles.xml
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@android:color/holo_green_dark</item>
</style>
Run Code Online (Sandbox Code Playgroud)
弹出码
Calendar mcurrentDate = Calendar.getInstance();
int mYear = mcurrentDate.get(Calendar.YEAR);
int mMonth = mcurrentDate.get(Calendar.MONTH);
int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker;
mDatePicker = new DatePickerDialog(context, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
Toast.makeText(context,"Selected Date " + + selectedday + "-" + ++selectedmonth + "-" + selectedyear ,Toast.LENGTH_SHORT).show();
}
}, mYear, mMonth, mDay);
mDatePicker.show();
Run Code Online (Sandbox Code Playgroud)
要在应用程序级别更改 DatePicker 颜色(日历模式),请定义以下属性。
<style name="MyAppTheme" parent="Theme.AppCompat.Light">
<item name="colorAccent">#ff6d00</item>
<item name="colorControlActivated">#33691e</item>
<item name="android:selectableItemBackgroundBorderless">@color/colorPrimaryDark</item>
<item name="colorControlHighlight">#d50000</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6492 次 |
| 最近记录: |