I am using a tabhost and load a layout-file using AddTabWithIcon.
Now I need to set by code the GradientDrawable of the layout-file. I could do it directly in the designer if it was a standard GradientDrawable but I am using RadialGradient which can only be set by code.
PS: I guess I could use AddTabWithIcon2 and setting by code the GradientDrawable of the panel loaded as a view but I prefer not since I would need to re-write a lot of code.
So the question, is it possible to set by code the GradientDrawable of a layout-file? Probably I have overlooked something but I cannot find it.
Here is my code which doesn't give the expected result:
B4X:
tabEPG.AddTabWithIcon("1",bmp1, bmp2,"page1.bal")
tabEPG.AddTabWithIcon("2",bmp3, bmp4,"page2.bal")
tabEPG.AddTabWithIcon("3",bmp5, bmp6,"page3.bal")
Dim GD_BG As GradientDrawable
GD_BG.Initialize("TOP_BOTTOM", Array As Int(Colors.RGB(102,102,102), Colors.RGB(26,26,26)))
Activity.Background = GD_BG
GeneralCode.SetRadialGradient(GD_BG, Activity.Height/2)
'Activity.Background = GD_BG 'wrong activity
'tabEPG.Background= GD_BG
You need to access the Panel that is created internally and is added to the TabHost.
This is a bit tricky. You can use this code:
B4X:
For i = 0 To th.TabCount - 1
th.CurrentTab = i 'This is required as the tab pages are not created before you access them.
Next
th.CurrentTab = 0
Dim r As Reflector
r.Target = th
Dim tabParentPanel As Panel
tabParentPanel = r.RunMethod("getTabContentView")
For i = 0 To tabParentPanel.NumberOfViews - 1
tabParentPanel.GetView(i).Drawable = ...
Next
I am glad you can read between the lines and understand what people are trying to say when they don't know, like me, the right terminology. That is also another important gift. In either case, you understood perfectly what I wanted to say.
As usual, you also furnished the solution to my problem. It works very nice.
I only had to change Drawable to Background (since Drawable was an unknown member) in this line:
B4X:
'tabParentPanel.GetView(i).Drawable '(not recognized)
tabParentPanel.GetView(i).Background 'just what I needed