Black and White designgs - how to switch between tham?

androidsoftcoder

Member
Licensed User
Longtime User
I would like that my app can be able to draw itself either with black text on white background or white texts on black background. Suppose that I have more than 50 objects on layout. So I must set at least 100 assignments operators to change colors of all objects (fore and back colors). It is not good idea as for me :(

Is the any short way of totally "repaint" all controls to one of predefined color scheme?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Something like:
B4X:
For i = 0 To Activity.NumberOfViews - 1
   Dim v As View
   v = Activity.GetView(i)
   v.Color = Colors.White
   If v Is Label Then 'handle labels and EditTexts
      Dim lbl As Label
      lbl = v
      lbl.TextColor = Colors.Black
   End If
Next
Note that the default background of Buttons and EditTexts is not a simple ColorDrawable. When you set the color property you are actually assigning a ColorDrawable as the background drawable.
 
Upvote 0

androidsoftcoder

Member
Licensed User
Longtime User
Something like:
Exactly what I need! Thanks!

There only strange effect during scrolling ListView - when I repaint all from black to white (activity and all objects), ListView become white, but when I scroll it, it reverts to black background while I scroll them and return to white when scroll is stopped. Is this can be fixed?

And one more problem raised: in black design some graphics in main activity menu is white pictograms which is look brilliantly on black background. But when I switch to white scheme - it... simply disappears. As far as I read in docs - main menu can be only setup at Activity_Create.
Is any possibility to reload images of main menu while app running?
And generally - is any possibility to change main menu after it was created?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Exactly what I need! Thanks!

There only strange effect during scrolling ListView - when I repaint all from black to white (activity and all objects), ListView become white, but when I scroll it, it reverts to black background while I scroll them and return to white when scroll is stopped. Is this can be fixed?

Also change listview.ScrollingBackgroundColor
 
Upvote 0

androidsoftcoder

Member
Licensed User
Longtime User
:sign0013:
ListView text colors does not change its color after
B4X:
lv.TwoLinesAndBitmap.Label.TextColor = LabelColor
lv.TwoLinesAndBitmap.SecondLabel.TextColor = SecondLabelColor
lv.ScrollingBackgroundColor = BackColor
Invalidate isn't working to :(
The only way to repaint - change orientation of device.
Any ideas how to fix ?
 
Upvote 0

androidsoftcoder

Member
Licensed User
Longtime User
Sorry once more, but I can't find an example with code where in loop enumerating 3 fields of ListView to obtain "stored" in ListView items values. I want to get sub, which copies all items from given listView into temp LV and than insert it back to original LV (in order to recreate it with new color). Somthing like that:
B4X:
Sub lv_Recreate(lv1 As ListView) As ListView
    Dim lv2 As ListView
      lv2.Initialize("")
      lv2.Clear
      For i = 0 To lv1.Size-1
         '  ...GetItem(i) must be here to point to next LV items - but I dont know how :(
         lv2.AddTwoLinesAndBitmap(l. lv1.TwoLinesAndBitmap.Label.Text, lv1.TwoLinesAndBitmap.SecondLabel.Text, lv1.TwoLinesAndBitmap.ImageView.Bitmap)
      Next 
      lv1.Clear
      For i = 0 To lv2.Size-1
         '  ...GetItem(i) must be here to point to next LV items - but I dont know how :(
      lv1.AddTwoLinesAndBitmap(lv2.TwoLinesAndBitmap.Label.Text, lv2.TwoLinesAndBitmap.SecondLabel.Text, lv2.TwoLinesAndBitmap.ImageView.Bitmap)
      Next 
End Sub
can you point me to the right example, or just correct my ugly code?
 
Last edited:
Upvote 0

androidsoftcoder

Member
Licensed User
Longtime User
as far as I found at moment the only working way to repaint ListView in another colors - is to completely recreate it:
1) Totaly remove it from parent
2) Initialize LV again
3) Set colors
4) Fill data "from the scratch"
It is not good practice for so commonly used function :(
 
Upvote 0
Top