Android Question 6.8 Button Background

Mashiane

Expert
Licensed User
Longtime User
Hi

I have created a new layout in 6.8, added a button, ran my function to change the button properties...

Button_PowderBlueWhite(btnApply)


B4X:
'Description: Function to customize your button with backcolor, textcolor, bordercolor, bordersize and radius
'Tag: button, backcolor, textcolor, radius

Public PowderBlue As Int = Colors.rgb(154,217,234)

Sub Button_PowderBlueWhite(btn As Button)
    Fancy_Button(btn,PowderBlue,Colors.White,2,2%x, Colors.black )
End Sub

Sub Fancy_Button(btn As Button, backColor As Int, textColor As Int, borderSize As Int, cornerRadius As Float, borderColor As Int)
    Dim dr As ColorDrawable
    dr.Initialize2(backColor, cornerRadius, borderSize, borderColor)
    btn.Background = dr
    btn.TextColor = textColor
    btn.Invalidate
End Sub

The Error logs..

B4X:
modmashiane_fancy_button (B4A line: 2458)
btn.Background = dr
java.lang.RuntimeException: Object should first be initialized (Button).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.ViewWrapper.setBackground(ViewWrapper.java:103)
    at com.Mash.restuarant.modmashiane._fancy_button(modmashiane.java:3936)
    at com.Mash.restuarant.modmashiane._button_powderbluewhite(modmashiane.java:1547)
    at com.Mash.restuarant.frmaddeditdivision._activity_create(frmaddeditdivision.java:372)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    at com.Mash.restuarant.frmaddeditdivision.afterFirstLayout(frmaddeditdivision.java:102)
    at com.Mash.restuarant.frmaddeditdivision.access$000(frmaddeditdivision.java:17)
    at com.Mash.restuarant.frmaddeditdivision$WaitForLayout.run(frmaddeditdivision.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5910)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

I have opened an old project with 6.8 that uses these methods, it however works..
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Moved to the questions forum.
B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("vAddEditWaiter")
   Activity.Color = Colors.white
   modThis.Button_PowderBlueWhite(Button1)
End Sub
There is no view named Button1 in vAddEddWaiter layout so it is never initialized.
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
Eish mfoweto haybo gotwe !!
 
Upvote 0
Top