Ads Inside Post

Search in This Blog

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) { }
  }
}
}