Android Question how to change activity color

a2stepper

Member
Licensed User
Longtime User
i'm using the long text codes and it uses two activities like:

Activity.LoadLayout("LongText"
scvText.Panel.LoadLayout("LongText1")

question is how to change the activity color in longtext1 in run time?

thanks.
paul
 

a2stepper

Member
Licensed User
Longtime User
ok thanks but i want to change the background color of the activity 'LongText1' to match the color of the
text background.
paul
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Not sure that I fully understand but you can do this...

B4X:
Activity.Color = lblText.Color

Or if longtext1 is a panel onto which you have loaded the labels in the designer then you will need to set it's color also in the same way.
 
Upvote 0

a2stepper

Member
Licensed User
Longtime User
yes it's a panel onto the label is used. i've tried to change
Activity.Color = lblText.Color
but does not change color of LongText1, just the LongText layout.
need to change the activity 'lonttext1' activity color.
paul
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Hi Paul,

The layout doesn't actually have an Activity as such, it is just a kind of placeholder name in the designer. So once you have created your layout(s) they can be loaded into an Activity of your choice or a Panel etc. It all depends on how you have designed your layout as to why the color is not changing as expected. I suspect that you may have used a Panel and placed the Labels onto this, in which case you would need to set the Panel color. Is it possible for you to upload the project or provide a sample of what you what to do?
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
It seems that I have misled you in that a label.color property is write only and it appears that it is not easy to get the color during runtime. That said, I saw a thread that suggested using the labels tag property to store the color used in the designer. Therefore here is a small sample which I hope proves useful.
 

Attachments

  • ColorTest.zip
    7.4 KB · Views: 242
Upvote 0

a2stepper

Member
Licensed User
Longtime User
Sub Globals
Dim lblText As Label
Dim scvText As ScrollView
Dim spnFont, spnFontSize As Spinner
Dim Times As Typeface
Dim StrUtil As StringUtils
Dim h As HttpJob
Dim txt As String
Private Panel1 As Panel
Private layout As Spinner
Dim gf As String
Dim sw As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Dim i As Int
Activity.LoadLayout("LongText")
Activity.AddMenuItem("Setup","setup")
scvText.Panel.LoadLayout("LongText1")
scvText.Height = 100%y - scvText.Top
Times = Typeface.LoadFromAssets("times.ttf")
filllayoutspinner
FillFontSpinner
FillFontSizeSpinner
lblText.Color=Colors.RGB(255,255,210)
lblText.TextColor=Colors.Black
spnFont.DropdownBackgroundColor = Colors.White
spnFont.Color = Colors.Blue
spnFontSize.DropdownBackgroundColor = Colors.White
spnFontSize.Color = Colors.Blue
Enc Sub

*** (( changing text color, text backgound color, and 'longtext1' activity color here))

Sub blackwhite
lblText.Color=Colors.White
lblText.TextColor=Colors.Black
*** ((need to change backgound of 'longtext1' to match text background))
End Sub

Sub whiteblack

End Sub

Sub blackyellow
scvText.Panel.LoadLayout("LongText1")
lblText.Color=Colors.RGB(255,255,161)
lblText.TextColor=Colors.Black
*** ((need to change backgound of 'longtext1' to match text background))
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Use code tag when posting code here!

codetag001.png

codetag002.png

codetag003.png
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I think I understand now what you want.
There are not twoactivities but only one activity.
The layout LongText1 with the lblText Label is loaded onto the internal panel of the ScrollView.
To change the color you should use this code:
lblText.Color = Colors.RGB(255,255,210)
scvText.Panel.Color = Colors.RGB(255,255,210)


Another possibility is to change this line
ht = StrUtil.MeasureMultilineTextHeight(lblText, txt)
into this one.
ht = Max(StrUtil.MeasureMultilineTextHeight(lblText, txt), scvText.Height)
This code sets the heights of lblText and scvText.Panel.
If the height is smaller than scvText.Height the ScrollView.Panel background is shown at the bottom.
With the change above the minimum heights of lblText and scvText.Panel are the scvText.Height, this way the ScrollView.Panel background will never be shown.
 
Upvote 0
Top