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

Unable to resolve <website url> Try checking the for validity Google Pagespeed Insights

Unable to resolve <website url> Try checking the for validity Google Pagespeed Insights   You have a website and want to test it'...

Ads Inside Post

Powered by Blogger.

Arsip