|
1 | 1 | package com.reactcommunity.rndatetimepicker; |
2 | 2 |
|
| 3 | +import android.app.AlertDialog; |
| 4 | +import android.app.DatePickerDialog; |
| 5 | +import android.content.Context; |
| 6 | +import android.content.DialogInterface; |
| 7 | +import android.content.res.Resources; |
| 8 | +import android.util.TypedValue; |
| 9 | +import android.widget.Button; |
| 10 | + |
| 11 | +import androidx.annotation.ColorInt; |
| 12 | +import androidx.annotation.ColorRes; |
| 13 | +import androidx.annotation.NonNull; |
| 14 | +import androidx.core.content.ContextCompat; |
3 | 15 | import androidx.fragment.app.DialogFragment; |
4 | 16 | import androidx.fragment.app.FragmentActivity; |
5 | 17 | import androidx.fragment.app.FragmentManager; |
@@ -30,4 +42,32 @@ public static void dismissDialog(FragmentActivity activity, String fragmentTag, |
30 | 42 | promise.reject(e); |
31 | 43 | } |
32 | 44 | } |
| 45 | + |
| 46 | + public static int getDefaultDialogButtonTextColor(@NonNull Context activity) { |
| 47 | + TypedValue typedValue = new TypedValue(); |
| 48 | + Resources.Theme theme = activity.getTheme(); |
| 49 | + theme.resolveAttribute(android.R.attr.textColorPrimary, typedValue, true); |
| 50 | + @ColorRes int colorRes = (typedValue.resourceId != 0) ? typedValue.resourceId : typedValue.data; |
| 51 | + @ColorInt int colorId = ContextCompat.getColor(activity, colorRes); |
| 52 | + return colorId; |
| 53 | + } |
| 54 | + |
| 55 | + @NonNull |
| 56 | + public static DialogInterface.OnShowListener setButtonTextColor(@NonNull Context activityContext, final AlertDialog dialog) { |
| 57 | + return presentedDialog -> { |
| 58 | + int textColorPrimary = getDefaultDialogButtonTextColor(activityContext); |
| 59 | + Button positiveButton = dialog.getButton(DatePickerDialog.BUTTON_POSITIVE); |
| 60 | + if (positiveButton != null) { |
| 61 | + positiveButton.setTextColor(textColorPrimary); |
| 62 | + } |
| 63 | + Button negativeButton = dialog.getButton(DatePickerDialog.BUTTON_NEGATIVE); |
| 64 | + if (negativeButton != null) { |
| 65 | + negativeButton.setTextColor(textColorPrimary); |
| 66 | + } |
| 67 | + Button neutralButton = dialog.getButton(DatePickerDialog.BUTTON_NEUTRAL); |
| 68 | + if (neutralButton != null) { |
| 69 | + neutralButton.setTextColor(textColorPrimary); |
| 70 | + } |
| 71 | + }; |
| 72 | + } |
33 | 73 | } |
0 commit comments