Skip to content

Commit f141ed3

Browse files
paulfthomasafohrman
authored andcommitted
[DatePicker][a11y] Fix contrast for hint color
PiperOrigin-RevId: 678345966
1 parent 13dbcfc commit f141ed3

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

lib/java/com/google/android/material/datepicker/RangeDateSelector.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import androidx.annotation.RestrictTo.Scope;
3636
import androidx.core.util.Pair;
3737
import androidx.core.util.Preconditions;
38+
import com.google.android.material.color.MaterialColors;
3839
import com.google.android.material.internal.ManufacturerUtils;
3940
import com.google.android.material.resources.MaterialAttributes;
4041
import com.google.android.material.textfield.TextInputLayout;
@@ -213,6 +214,12 @@ public View onCreateTextInputView(
213214
final TextInputLayout endTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_end);
214215
EditText startEditText = startTextInput.getEditText();
215216
EditText endEditText = endTextInput.getEditText();
217+
Integer hintTextColor =
218+
MaterialColors.getColorOrNull(root.getContext(), R.attr.colorOnSurfaceVariant);
219+
if (hintTextColor != null) {
220+
startEditText.setHintTextColor(hintTextColor);
221+
endEditText.setHintTextColor(hintTextColor);
222+
}
216223
if (ManufacturerUtils.isDateInputKeyboardMissingSeparatorCharacters()) {
217224
// Using the URI variation places the '/' and '.' in more prominent positions
218225
startEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

lib/java/com/google/android/material/datepicker/SingleDateSelector.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import androidx.annotation.RestrictTo;
3434
import androidx.annotation.RestrictTo.Scope;
3535
import androidx.core.util.Pair;
36+
import com.google.android.material.color.MaterialColors;
3637
import com.google.android.material.internal.ManufacturerUtils;
3738
import com.google.android.material.resources.MaterialAttributes;
3839
import com.google.android.material.textfield.TextInputLayout;
@@ -113,6 +114,11 @@ public View onCreateTextInputView(
113114

114115
TextInputLayout dateTextInput = root.findViewById(R.id.mtrl_picker_text_input_date);
115116
EditText dateEditText = dateTextInput.getEditText();
117+
Integer hintTextColor =
118+
MaterialColors.getColorOrNull(root.getContext(), R.attr.colorOnSurfaceVariant);
119+
if (hintTextColor != null) {
120+
dateEditText.setHintTextColor(hintTextColor);
121+
}
116122
if (ManufacturerUtils.isDateInputKeyboardMissingSeparatorCharacters()) {
117123
// Using the URI variation places the '/' and '.' in more prominent positions
118124
dateEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

lib/javatests/com/google/android/material/datepicker/RangeDateSelectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class RangeDateSelectorTest {
5858

5959
@Before
6060
public void setupMonthAdapters() {
61-
ApplicationProvider.getApplicationContext().setTheme(R.style.Theme_MaterialComponents_Light);
61+
ApplicationProvider.getApplicationContext().setTheme(R.style.Theme_Material3_Light);
6262
activity = Robolectric.buildActivity(AppCompatActivity.class).setup().get();
6363
context = activity.getApplicationContext();
6464
res = context.getResources();

lib/javatests/com/google/android/material/datepicker/SingleDateSelectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class SingleDateSelectorTest {
5656

5757
@Before
5858
public void setupMonthAdapters() {
59-
ApplicationProvider.getApplicationContext().setTheme(R.style.Theme_MaterialComponents_Light);
59+
ApplicationProvider.getApplicationContext().setTheme(R.style.Theme_Material3_Light);
6060
activity = Robolectric.buildActivity(AppCompatActivity.class).setup().get();
6161
context = activity.getApplicationContext();
6262
res = context.getResources();

0 commit comments

Comments
 (0)