Android Question EditText cursor color

lymey

Active Member
Licensed User
Longtime User
Hi,
I have been trying to figure out how to change the cursor color in an EditText - mainly because the default is white in 4.x, and I dont want black/dark backgrounds in EditText boxes!

I looked on the net, and the rsults for java developers involve changing .xml layout files, which I believe we can't do using B4A unless you create a library??

Anyway, is there a way in B4A of changing the EditText cursor color to black not white?
Use Reflection?

Thanks!
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I've been away for about 6 months getting settled in a new job, but in my last couple libraries I had methods for changing themes in code for this very thing. When called it would change the theme for the activity which had the effect of modifying the theme for the next control you added by code. This allowed you to set themes on the fly and keep your main theme so the rest of your app doesn't change. This is the JAVA code a Library could be made from:

B4X:
    /**
    * Set the Theme of the Activity to one of the Theme_ Constants.
    */
    public void SetTheme(int ThemeID) {
        ba.activity.setTheme(ThemeID);
    }

    /**
    * android.R.style.Theme_Black (Android 1.0+/API1)
    */
    public static int getTheme_Black() { return 16973832;}
 
    /**
    * android.R.style.Theme_DeviceDefault (Android 4.0+/API14)
    */
    public static int getTheme_DeviceDefault() {if (android.os.Build.VERSION.SDK_INT > 13) {return 16974120;}else {return 16973836;}}
 
    /**
    * android.R.style.Theme_Holo (Android 3.0+/API11)
    */
    public static int getTheme_Holo() {if (android.os.Build.VERSION.SDK_INT > 10) {return 16973931;}else {return 16973836;}}
 
    /**
    * android.R.style.Theme_Holo_Light (Android 3.0+/API11)
    */
    public static int getTheme_HoloLight() {if (android.os.Build.VERSION.SDK_INT > 10) {return 16973934;}else {return 16973836;}}
 
    /**
    * android.R.style.Theme_Light (Android 1.0+/API1)
    */
    public static int getTheme_Light() { return 16973836;}
 
    /**
    * android.R.style.Theme_Translucent (Android 1.0+/API1)
    */
    public static int getTheme_Translucent() { return 16973839;}
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
B4X:
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
or
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")
Thanks for this - what I needed as well.
It should be noted however that changing the theme to Holo.light also changes the default text color for controls from white to black. I had to add code to specifically set the controls text back to white where applicable.
 
Upvote 0
U

unba1300

Guest
I had to deal with this as well, so added SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light") to the Manifest and all is well. But I'd like to change the color of the title background. I tried Activity.TitleColor = Colors.Red and it did not have any effect. Anyone know if I can also change the color or background of the title bar after setting the theme in the manifest? Thanks.
 
Upvote 0
Top