Android Question Strange bug when using GradientDrawable

cobra666

Member
Licensed User
Longtime User
Hi

Found a strange bug when using GradientDrawable.
Wrinting an app that will use color themes.

1. Test Label 1 and 3 has color from code, test label 2 has fixed colors
2. Run the app.
3. Press POPUP
4. Just touch the textbox and watch what happens with the test label.
5. Close popup and press fix
6. Now open popup again and do the same
7. Now there is no problem

Why is test label 1 the only one that is doing this ??
 

Attachments

  • Screenshot_2020-08-12-13-11-07.png
    Screenshot_2020-08-12-13-11-07.png
    54.1 KB · Views: 207
  • Screenshot_2020-08-12-13-11-13.png
    Screenshot_2020-08-12-13-11-13.png
    107.2 KB · Views: 199
  • bug_GradientDrawable.zip
    9.9 KB · Views: 194

Erel

B4X founder
Staff member
Licensed User
Longtime User
Moved to the questions forum.

You should never reused drawables.
Why aren't you using anchors???

Fixed code:
B4X:
Sub Globals
    Dim clrs(2) As Int
    Dim background As Int
    
    Private Label1 As Label
    Private Label2 As Label
    Private Panel1 As Panel
    Private EditText1 As EditText
    Private Panel2 As Panel
    Private Label3 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
    Panel1.Width=GetDeviceLayoutValues.Width
    Label1.Width=GetDeviceLayoutValues.Width
    Label3.Width=GetDeviceLayoutValues.Width
    colorsetting1
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub colorsetting1
    clrs(0) = 0xFF00008B
    clrs(1) = 0xFF282828
    background=0xff4c434d
    Panel1.Color=background
    Panel2.Color=background
    Label1.Background=CreateGradientDrawable
    Label2.Background=CreateGradientDrawable
End Sub

Sub CreateGradientDrawable As GradientDrawable
    Dim grdr As GradientDrawable
    grdr.Initialize("LEFT_RIGHT",clrs)
    Return grdr
End Sub

Sub Button1_Click
    Dim kb As Phone
    kb.HideKeyboard(Activity)
    Panel2.Visible=False
End Sub

Sub button_popup_Click
    EditText1.Text=""
    Panel2.Visible=True
End Sub

Sub button_fix_Click
    Label1.Background = CreateGradientDrawable
End Sub
 
Upvote 0
Top