Android Code Snippet Change EditText Colors

Erel

Administrator
Staff member
Licensed User


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
Top