Fix button appearance for older devices

+ Buttons on API < 29 now all have the same color for the customTheme
+ This can be worked on again, if someone figures out how to dynamically 
change button colors on older android APIs
This commit is contained in:
Finn M Glas 2020-05-25 18:44:57 +02:00
parent 6862be3521
commit d4ea809569
No known key found for this signature in database
GPG key ID: 25037A2E81AB459C
4 changed files with 18 additions and 8 deletions

View file

@ -66,7 +66,7 @@ class MainActivity : AppCompatActivity(),
when (currentTheme) { when (currentTheme) {
"dark" -> R.style.darkTheme "dark" -> R.style.darkTheme
"finn" -> R.style.finnmglasTheme "finn" -> R.style.finnmglasTheme
else -> R.style.finnmglasTheme else -> R.style.customTheme
} }
) )
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)

View file

@ -34,7 +34,7 @@ class SettingsActivity : AppCompatActivity() {
when (getSavedTheme(this)) { when (getSavedTheme(this)) {
"dark" -> R.style.darkTheme "dark" -> R.style.darkTheme
"finn" -> R.style.finnmglasTheme "finn" -> R.style.finnmglasTheme
else -> R.style.finnmglasTheme else -> R.style.customTheme
} }
) )

View file

@ -8,10 +8,7 @@ import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.pm.ResolveInfo import android.content.pm.ResolveInfo
import android.graphics.Bitmap import android.graphics.*
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.PorterDuff
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -325,6 +322,9 @@ fun getDominantColor(bitmap: Bitmap?): Int {
fun setButtonColor(btn: Button, color: Int) { fun setButtonColor(btn: Button, color: Int) {
if (Build.VERSION.SDK_INT >= 29) if (Build.VERSION.SDK_INT >= 29)
btn.background.colorFilter = BlendModeColorFilter(color, BlendMode.MULTIPLY) btn.background.colorFilter = BlendModeColorFilter(color, BlendMode.MULTIPLY)
else else {
btn.background.setColorFilter(color, PorterDuff.Mode.MULTIPLY) // not setting it here, unable to find a good alternative
// I tried:
// btn.background.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
}
} }

View file

@ -31,6 +31,16 @@
<item name="android:windowAnimationStyle">@style/WindowFadeTransition</item> <item name="android:windowAnimationStyle">@style/WindowFadeTransition</item>
</style> </style>
<!-- Custom theme -->
<style name="customTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColor">#ffffff</item>
<item name="android:buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
<item name="colorButtonNormal">#252827</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowAnimationStyle">@style/WindowFadeTransition</item>
</style>
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert"> <style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColor">#000000</item> <item name="android:textColor">#000000</item>
</style> </style>