Android Question Change background/text color buttons CustomLayoutDialog

JDS

Active Member
Licensed User
Longtime User
I'm using the following code in a CustomLayoutDialog.
Now i want the backgroundcolors of the title and textcolor of the ok / cancel buttons to be different (for example background red, textcolor white). How can this be done? I can't figure it out.

B4X:
Dim cd, cd2 As ColorDrawable
        cd2.Initialize(Globaal.COLOR_ENABLE,5dip)
     
        Dim sf As Object = MsgboxLM.ShowAsync(Language.Vertaal(sLosopmHeader), Language.Vertaal("Ok"), "", "", Null, False)
        MsgboxLM.SetSize(85%x, 400dip)
        Dim cs As CSBuilder
        Dim jo As JavaObject = sf
        cd.Initialize2(Colors.White, 4dip, 4dip, Globaal.COLOR_ENABLE)
        jo.RunMethod("setTitle", Array(cs.Initialize.Color(Colors.Black).Append(sLosopmHeader).PopAll))
        jo.RunMethodjo("getWindow", Null).RunMethod("setBackgroundDrawable", Array(cd))
        Wait For (sf) Dialog_Ready(pnl As Panel)
        pnl.LoadLayout("Dialogtekst")
        MsgboxLM.GetButton(DialogResponse.POSITIVE).Enabled = True
        oLblMsgBox.Text=sLosopm.Trim
        Wait For (sf) Dialog_Result(res As Int)
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can change the buttons background and text color with:
B4X:
Wait For (sf) Dialog_Ready (DialogPanel As Panel)
Dim drawable As ColorDrawable
drawable.Initialize(Colors.Blue, 10dip)
cd.GetButton(DialogResponse.POSITIVE).Background = drawable
Dim cs As CSBuilder
cs.Initialize.Color(Colors.Red).Append("YES").PopAll
cd.GetButton(DialogResponse.POSITIVE).Text = cs
 
Upvote 0

JDS

Active Member
Licensed User
Longtime User
Didn't work completely.
Changed it to
B4X:
Wait For (sf) Dialog_Ready(pnl As Panel)
       
Dim drawable As ColorDrawable
drawable.Initialize(color.blue, 5dip) 'change background ok button
cd.GetButton(DialogResponse.POSITIVE).Background = drawable
Dim cs As CSBuilder
cs.Initialize.Color(Colors.White).Append("Ok").PopAll
cd.GetButton(DialogResponse.POSITIVE).TextColor = Colors.White 'change textcolor button

however this doesn't change the title background. Or is there a way to hide the title and add a label to the customdialog?
 
Upvote 0

JDS

Active Member
Licensed User
Longtime User
Do you mean a custom theme with appcompat?
In the examples I can only find the color name of "Actionbar" "Statusbar" and "NavigationBar".

I just need the bar behind "LogisticManager mobile" blue like the buttons below (see picture).
 

Attachments

  • Screenshot_20181116-105644[1].png
    46.7 KB · Views: 207
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…