For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Friday, August 30, 2013

Change text background color in android

Change text background color in android

static Handler h;
protected void onCreate() {
this.h = new Handler() {
    public void handleMessage(Message msg) {
        switch (msg.what) {
                case 0:
        Random rnd = new Random();
            int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
            txtMessage.setBackgroundColor(
color);
                break;
               }
               super.handleMessage(msg);
           }};
    ChangeBGColor u =new ChangeBGColor("", "");
        new Thread(u).start();
}

in other class

import android.os.Message;
public class ChangeBGColor implements Runnable {
 public ChangeBGColor(String inputFileName,String surl) {
 }
 @Override
 public void run() {
  boolean ans=false;
  int cc=0;
  while(ans!=true) {
    try {
    Thread.sleep(2000);
    Message message= new Message();
    cc++;
    message.obj = " "+cc;
    cc--;
    MainActivity.h.sendMessage(message);
    } catch(Exception ee) { }
  }
}
}
Share:

0 comments:

Post a Comment

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip