Android Question [SOLVED] - Changing background colour of B4XDialog

rleiman

Well-Known Member
Licensed User
Greetings,

I'm trying to change the background colour of a B4XDialog I started to use but the app crashes with this error in the logs. It crashes on the comented out line.

B4X:
java.lang.NumberFormatException: For input string: "(GradientDrawableWithCorners) anywheresoftware.b4a.objects.drawable.ColorDrawable$GradientDrawableWithCorners@e4beb1"
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
    at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.lang.Double.parseDouble(Double.java:538)
    at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:684)
    at b4a.natures.song.b4xmainpage$ResumableSub_ButtonClearCreatureSettings_Click.resume(b4xmainpage.java:426)
    at b4a.natures.song.b4xmainpage._buttonclearcreaturesettings_click(b4xmainpage.java:399)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7869)
    at android.widget.TextView.performClick(TextView.java:14958)
    at android.view.View.performClickInternal(View.java:7838)
    at android.view.View.access$3600(View.java:886)
    at android.view.View$PerformClick.run(View.java:29362)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8125)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

Code to call and respond to the B4XDialog:
Sub ButtonClearCreatureSettings_Click
  
    Dim p As B4XView = xui.CreatePanel("")
    cdBackgroundColour.Initialize(Colors.ARGB(150, 0, 0, 0), 0)
'    p.Color = cdBackgroundColour ' Assign the colour to panel.
    p.SetLayoutAnimated(0, 0, 50dip, 300dip, 150dip)
    p.LoadLayout("NotificationWindow")
      
    LabelNotification.Text = "Are you sure you want to clear the creature settings?"
    dialog.Title = "Clear Creature Settings"
    dialog.PutAtTop = True

    Wait For (dialog.ShowCustom(p, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log("Ok to clear.")
    End If
End Sub

I would also like to make the dialog have rounded corners if that's possible so it matches the rest of the app.
 
Last edited:

mangojack

Well-Known Member
Licensed User
Presuming cdBackgroundColour is declared As ColorDrawable .. It is set to the Panel.Background prop , Not Color.
And as .Background is not availiable to B4XView you could cast the view to a Panel.

ColorDrawable.Initialize2 allows setting Corner Radius & Border Color as well

B4X:
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 50dip, 300dip, 150dip)
    p.LoadLayout("NotificationWindow")

    cdBackgroundColour.Initialize2(Colors.ARGB(150, 0, 0, 0), 10dip, 2dip, Colors.Red)
    Dim pnl As Panel = p
    pnl.Background = cdBackgroundColour ' Assign the colour to panel.


ps: personally I think the rounded corners (with or without borders) detract from a modern dialog look.
 
Last edited:
Upvote 0

rleiman

Well-Known Member
Licensed User
Presuming cdBackgroundColour is declared As ColorDrawable .. It is set to the Panel.Background prop , Not Color.
And as .Background is not availiable to B4XView you could cast the view to a Panel.

ColorDrawable.Initialize2 allows setting Corner Radius & Border Color as well

B4X:
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 50dip, 300dip, 150dip)
    p.LoadLayout("NotificationWindow")

    cdBackgroundColour.Initialize2(Colors.ARGB(150, 0, 0, 0), 10dip, 2dip, Colors.Red)
    Dim pnl As Panel = p
    pnl.Background = cdBackgroundColour ' Assign the colour to panel.


ps: personally I think the rounded corners (with or without borders) detract from a modern dialog look.
Yes, it's declared as ColorDrawable.

Thanks so much! That's very helpful.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Thanks so much for the link. The best part of what is in that example is that you are using the 0x notations for your colours. We use Figma and the colours shown for the item colours use that same number notation. Now anywhere on B4A that requires colours I will use that notation preceded by 0x. Previously when we wanted to use the same colours as in Figma we had to do a lookup and conversion to RGB notation. That saves so much time. 👏
 
Upvote 0
Top