how to change colours in a .xml defined layout in run time

by ckloch » Wed, 16 Jun 2010 20:05:26 GMT

Sponsored Links
 Dear friends,

I am developing a small app that should inform the drivers whether his
current speed matches the preferred one in order to avoid stopping for
the red light.

I have no probelms to calculate the relative speed of the vehicle and
compare it with the preferred speed in order to determine and inform
the driver whether his speed is appropriate for crossing the traffic
light when it is green, or he needs to slow down or speed up.

But, I would be very thankful if you can help me to display this

My current idea is to draw a traffic light (in red and green) on the
screen in .xml, using 11 equally sized bars. Hereby, I can show
whether the speed fits perfectly (then bar 6 should be black), or
there is no room for delay (then bar 4 should be black)
So far, I have made the traffic light in .xml.

My next step is to change the color of one of the bars dependent on
how the relative speed matches the shifts in the traffic light.
In theory it seems to be easy, but I would highly appreciate your help
on how to do this in Android as I cannot see how I start changing the
colours of the individual bar in the screen after initially defining
the screen.

There might be other and better ways to implement this than .xml

I would appreciate your help;

Best regards


Other Threads

1. WakeLock acquire(timeout) Runtime exception

Hi All,
I get a Runtime exception when my wait lock gets expired . Is it
because I am trying to release a lock that was acquired with a

I am using the following code to acquire the wakelock before a view is

        private PowerManage.WakeLock  wakeLock;
        public  void    acquireWakeLock(Context ctx){
                if(wakeLock != null && wakeLock.isHeld())       
                PowerManager pm = (PowerManager)
                wakeLock = 

      /** this is called only from the above function **/
        private    void releaseWakeLock(){
                if(wakeLock != null && wakeLock.isHeld()){
                wakeLock = null;



2. Multiple screen support Android Web Phonegap


I developed an application using Phonegap for Multiple screen support

Problem: for multiple screen support how to make  a common css file.

I used the tag

<meta name="viewport" content="width=device-width, initial-scale=1.0,
user-scalable=no"> in html file.

so that same css is applied for all the screens except MDPI Large

WVGA800* (480x800)
WVGA854* (480x854)  For these screens the height is limited to the
HVGA screen height(480). It is not auto scaling to the actual screen

How to solve these problem.


3. Scaling ImageView "rightCrop"

4. Reg: Develop Android Device Driver for s3c2440

5. Downgrade / Upgrade Firmware archos family

6. problem with use " /system/bin/rild " dynamically

7. YUV to MPEG image conversion