Merge pull request #2093 from osodebailar/bugfix/toast-text-color

fix toast text color especially on android 11 and above
This commit is contained in:
Milos Kozak 2022-09-22 09:41:03 +02:00 committed by GitHub
commit c031770ab1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 5 deletions

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.utils.resources.getThemeColor
object ToastUtils { object ToastUtils {
@ -76,7 +77,15 @@ object ToastUtils {
fun showToastInUiThread(ctx: Context?, string: String?) { fun showToastInUiThread(ctx: Context?, string: String?) {
val mainThread = Handler(Looper.getMainLooper()) val mainThread = Handler(Looper.getMainLooper())
mainThread.post { Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show() } mainThread.post {
val toast: Toast =
Toast.makeText(
ctx,
HtmlHelper.fromHtml("<font color='" + ContextThemeWrapper(ctx, R.style.AppTheme).getThemeColor(R.attr.toastBaseTextColor) + "'>" + string + "</font>"),
Toast.LENGTH_SHORT
)
toast.show()
}
} }
fun showToastInUiThread( fun showToastInUiThread(

View file

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/toast_border_ok"> android:background="?attr/toastBackgroundColor">
<ImageView <ImageView
android:id="@android:id/icon" android:id="@android:id/icon"
@ -26,7 +26,7 @@
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:layout_marginEnd="18dp" android:layout_marginEnd="18dp"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:textColor="?attr/toastBaseTextColor" android:textColor="?attr/defaultTextColor"
android:textSize="18sp" android:textSize="18sp"
tools:ignore="RtlHardcoded" tools:ignore="RtlHardcoded"
tools:text="Toast goes here..." /> tools:text="Toast goes here..." />

View file

@ -109,7 +109,7 @@
<!-- Toasts--> <!-- Toasts-->
<color name="toastBorder">#666666</color> <color name="toastBorder">#666666</color>
<color name="toastBase">#ffffff</color> <color name="toastBase">#000000</color>
<color name="toastOk">#77dd77</color> <color name="toastOk">#77dd77</color>
<color name="toastError">#ff0400</color> <color name="toastError">#ff0400</color>
<color name="toastWarn">#FF8C00</color> <color name="toastWarn">#FF8C00</color>

View file

@ -95,6 +95,7 @@
<item name="defaultBackground">@color/defaultBackground</item> <item name="defaultBackground">@color/defaultBackground</item>
<!---Toast --> <!---Toast -->
<item name="toastBaseTextColor">@color/toastBase</item> <item name="toastBaseTextColor">@color/toastBase</item>
<item name="toastBackgroundColor">@color/buttonBackground</item>
<!---Dialog Helper --> <!---Dialog Helper -->
<item name="materialAlertDialogTheme">@style/DialogTheme</item> <item name="materialAlertDialogTheme">@style/DialogTheme</item>
<item name="android:alertDialogTheme">@style/DialogTheme</item> <item name="android:alertDialogTheme">@style/DialogTheme</item>

View file

@ -65,6 +65,7 @@
<attr name="defaultBackground" format="reference|color" /> <attr name="defaultBackground" format="reference|color" />
<!---Toast --> <!---Toast -->
<attr name="toastBaseTextColor" format="reference|color" /> <attr name="toastBaseTextColor" format="reference|color" />
<attr name="toastBackgroundColor" format="reference|color" />
<declare-styleable name="NumberPicker"> <declare-styleable name="NumberPicker">
<attr name="customContentDescription" format="string" /> <attr name="customContentDescription" format="string" />
</declare-styleable> </declare-styleable>

View file

@ -111,7 +111,7 @@
<!-- Toasts--> <!-- Toasts-->
<color name="toastBorder">#666666</color> <color name="toastBorder">#666666</color>
<color name="toastBase">#ffffff</color> <color name="toastBase">#000000</color>
<color name="toastOk">#77dd77</color> <color name="toastOk">#77dd77</color>
<color name="toastError">#ff0400</color> <color name="toastError">#ff0400</color>
<color name="toastWarn">#FF8C00</color> <color name="toastWarn">#FF8C00</color>

View file

@ -100,6 +100,7 @@
<item name="defaultBackground">@color/white</item> <item name="defaultBackground">@color/white</item>
<!---Toast --> <!---Toast -->
<item name="toastBaseTextColor">@color/toastBase</item> <item name="toastBaseTextColor">@color/toastBase</item>
<item name="toastBackgroundColor">@color/colorLightGray</item>
<!---Dialog Helper --> <!---Dialog Helper -->
<item name="materialAlertDialogTheme">@style/DialogTheme</item> <item name="materialAlertDialogTheme">@style/DialogTheme</item>
<item name="android:alertDialogTheme">@style/DialogTheme</item> <item name="android:alertDialogTheme">@style/DialogTheme</item>