【问题标题】:How to change the color of DatePicker Dialog如何更改 DatePicker 对话框的颜色
【发布时间】:2013-04-10 13:12:37
【问题描述】:

我喜欢改变 DatePicker Dialog 的颜色。我将对话框加载为

@SuppressLint("NewApi")
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

       @SuppressLint("NewApi")
    @Override
       public Dialog onCreateDialog(Bundle savedInstanceState) {
            // Use the current date as the default date in the picker
            final Calendar c = Calendar.getInstance();
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);

            // Create a new instance of DatePickerDialog and return it
            return new DatePickerDialog(getActivity(), this, year, month, day);
      }

      public void onDateSet(DatePicker view, int year, int month, int day) {
           // Do something with the date chosen by the user


      }


}

@SuppressLint("NewApi")
public void showDatePickerDialog(View v) {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(getFragmentManager(), "datePicker");//show(getSupportFragmentManager(), "datePicker");
}

当它加载对话框时,它是白色背景。如何更改显示颜色,如第二张图片所示? 谢谢

【问题讨论】:

  • 在这里查看答案 - stackoverflow.com/questions/6729697/…
  • 那个使用 AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.popup_theme));并改变主题。但对我来说是我使用 newFragment.show(getFragmentManager(), "datePicker");我怎样才能改变主题?

标签: android


【解决方案1】:

根据您的查询,您必须创建自定义对话框主题并在custom_theme.xml 中设置现在只需根据您的API 版本进行设置。

首先,在值中添加一个像这样的主题.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- Any customizations for your app running on pre-3.0 devices here -->
    </style>
</resources> 

然后,在 res 目录下创建一个名为“values-v11”(Android 3.0+)的目录,并放入一个像这样的themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
        <!-- Any customizations for your app running on 3.0+ devices here -->
    </style>
</resources>

最后在res目录下创建一个名为“values-v14”(Android 4.0+)的目录,并创建一个themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
        <!-- Any customizations for your app running on 4.0+ devices here -->
    </style>
</resources>  

For More Details查看链接并关注它。

希望您从他们那里得到一些想法并解决您的问题。

祝你好运。

【讨论】:

    【解决方案2】:

    这是我会尝试的。对于 Android How to use Holo.Light theme, and fall back to 'Light' on pre-honeycomb devices?

    我不能 100% 确定这会改变您的警报对话框,因为我没有广泛使用浅色主题,因此您可能需要从浅色主题中编辑一个或两个属性以获取编辑文本的背景要轻。

    【讨论】:

      猜你喜欢
      • 2015-04-28
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 2012-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多