Android Question how to change activity color

Discussion in 'Android Questions' started by a2stepper, Mar 4, 2015.

  1. a2stepper

    a2stepper Member Licensed User

    i'm using the long text codes and it uses two activities like:


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

  2. klaus

    klaus Expert Licensed User

    You must change the color of lblText with:
    lblText.Color = MyColor
    You might also change the TextColor.
    lblText.TextColor = MyTextColor
  3. a2stepper

    a2stepper Member Licensed User

    ok thanks but i want to change the background color of the activity 'LongText1' to match the color of the
    text background.
  4. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Not sure that I fully understand but you can do this...

    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.
  5. a2stepper

    a2stepper Member Licensed 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.
  6. RandomCoder

    RandomCoder Well-Known Member Licensed 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?
  7. RandomCoder

    RandomCoder Well-Known Member Licensed 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.

    Attached Files:

  8. a2stepper

    a2stepper Member Licensed 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
    scvText.Height = 100%y - scvText.Top
    Times = Typeface.LoadFromAssets("times.ttf")
    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
    *** ((need to change backgound of 'longtext1' to match text background))
    End Sub

    Sub whiteblack

    End Sub

    Sub blackyellow
    *** ((need to change backgound of 'longtext1' to match text background))
    End Sub
  9. DonManfred

    DonManfred Expert Licensed User

    Use code tag when posting code here!

  10. klaus

    klaus Expert Licensed 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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice