Android Question Get TextColor of Disabled Button?

Arf

Well-Known Member
Licensed User
Longtime User
I am trying to save the text color of a disabled button when it's in the disabled state. Disabling the button and storing the content of button.TextColor always seems to come out wit the same value, which doesn't seem to match what I expect.

I guess the color is being decided by android at a lower level, in accordance with the scheme selected.

Is there any way I can determine what color the text of a disabled button is, programatically?
 

ronell

Well-Known Member
Licensed User
Longtime User
enabled and disabled button has the same textcolor. i guess thats why they have the same value
B4X:
Sub Activity_Create(FirstTime As Boolean)
  
    Activity.LoadLayout("main")
    Log(Button1.TextColor)
End Sub

Sub Button1_Click
    Button1.Enabled = False
  
    Log(Button1.TextColor)
End Sub
B4X:
log

-14876486

-14876486
 
Last edited:
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Ah, I'm using the theme "Theme.Holo.Light", which has light text on inactive buttons and dark text on active buttons, but Button.TextColor always reads the same value whether active or not.

I do need to manually set the text color of one of my buttons though, and when it's inactive I manually set it to Colors.LightGrey, which seems right compared to my other buttons that are colored by the theme, I just wanted to instead try to set that color to the color of another inactive button instead of Color.LightGrey, as then if I changed the theme, it would just work, intead of me having to change that Color.LightGrey to Color.WhateverTheNewThemeInactiveTextColorIs.

I can't seem to do that though - programatically determine the text color of an inactive button as dictated by the theme.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm using the theme "Theme.Holo.Light"
Better way to set light theme: https://www.b4x.com/android/forum/threads/b4a-v5-80-beta-is-released.63300/#content

Getting the colors:
B4X:
Dim jo As JavaObject = Button1
Dim colorsStateList As JavaObject = jo.RunMethod("getTextColors", Null)
Dim s As StateListDrawable 'ignore
Log("disabled: ")
Log(colorsStateList.RunMethod("getColorForState", Array(Array As Int(s.State_Disabled), 0)))
Log("enabled: ")
Log(colorsStateList.RunMethod("getColorForState", Array(Array As Int(s.State_Enabled), 0)))
 
Upvote 0
Top