Android Code Snippet Change EditText Colors

SS-2017-12-26_09.04.32.png


1. Add:
B4X:
#AdditionalJar: com.android.support:support-compat

2.
B4X:
Sub SetBackgroundTintList(View As View,Active As Int, Enabled As Int)
   Dim States(2,1) As Int
   States(0,0) = 16842908     'Active
   States(1,0) = 16842910    'Enabled
   Dim Color(2) As Int = Array As Int(Active,Enabled)
   Dim CSL As JavaObject
   CSL.InitializeNewInstance("android.content.res.ColorStateList",Array As Object(States,Color))
   Dim jo As JavaObject
   jo.InitializeStatic("android.support.v4.view.ViewCompat")
   jo.RunMethod("setBackgroundTintList", Array(View, CSL))
End Sub

Example:
B4X:
SetBackgroundTintList(EditText1, Colors.Red, 0xFF0020FF)

It will only be changed on Android 5+.
 

ilan

Expert
Licensed User
Longtime User

noeleon

Active Member
Licensed User
yes it's a lot easier than manually editing layout xml files which i'm too lazy to try.
 
Top