简体   繁体   English

Android:某些设备上的DatePicker微调器文本颜色为白色

[英]Android: DatePicker spinner text color white on some devices

I realized that on some devices my DatePicker 's spinners don't show because the text is white instead of black (as it should be). 我意识到在某些设备上, DatePicker的微调框不显示,因为文本是白色而不是黑色(应该是黑色)。

Example with a Honor 5C: 荣誉5C的示例:

在此处输入图片说明

Example with a One Plus 5: One Plus 5的示例:

在此处输入图片说明

I realized it by setting a black background color instead: 我是通过设置黑色背景色来实现的:

在此处输入图片说明

I tried to change a lot of different attributes but nothing worked. 我试图更改许多不同的属性,但没有任何效果。

Here is the underlying code: 这是基础代码:

final AlertDialog.Builder datePickerDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialog);
final View view = fragment.getActivity().getLayoutInflater().inflate(R.layout.views_form_pick_date_dialog_day, null);
final AppCompatTextView datePickerDialogTitle = (AppCompatTextView) view.findViewById(R.id.views_form_pick_date_dialog_title);
final DatePicker datePickerDialogSpinner = (DatePicker) view.findViewById(R.id.views_form_pick_date_dialog_spinner);
datePickerDialogSpinner.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
datePickerDialog.setView(view);
datePickerDialog.show();

The XML layout associated: 关联的XML布局:

R.layout.views_form_pick_date_dialog_day R.layout.views_form_pick_date_dialog_day

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.AppCompatTextView style="@style/TextViewBody"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/style_size_space_medium"
        android:background="@color/style_color_red"
        android:text="@string/app_name"
        android:id="@+id/views_form_pick_date_dialog_title" />

    <DatePicker
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/views_form_pick_date_dialog_title"
        android:calendarViewShown="false"
        android:datePickerMode="spinner"
        android:id="@+id/views_form_pick_date_dialog_spinner" />

</RelativeLayout>

Thanks for your help. 谢谢你的帮助。

Try this, 尝试这个,

Use this as your Activity style. 使用它作为您的活动样式。

<style parent="Theme.AppCompat.Light.NoActionBar" name="MyActivityTheme">

<!-- Customize your theme here. -->

<item name="colorPrimary">@color/colorPrimary</item>

<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

<item name="android:textColor">@color/black</item>

<item name="colorAccent">@color/colorAccent</item>

<item name="android:textColorPrimary">@color/black</item>


</style>

and in your manifest add its as your Activity theme. 并在清单中添加其作为“活动”主题。

<activity
        android:name="yourActivity"
        android:theme="@style/MyActivityTheme"/>

it may help you. 它可能会帮助您。

Change the datePicker textColor by simply doing this: 只需执行以下操作即可更改datePicker textColor:

 <DatePicker
        android:id="@+id/start_date_text"
        android:layout_width="400dp"
        android:layout_height="190dp"
        android:datePickerMode="spinner"
        android:calendarViewShown="false"
        style="@style/MyDatePicker" />

and style 和风格

<style name="MyDatePicker" parent="android:Widget.Material.Light.DatePicker">
     <item name="android:textColorPrimary">@color/Black</item>
</style>

Set style for your date picker 为日期选择器设置样式

<style name="datepicker" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/primary</item>
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM