[ios]代码库
private TextView customView;
private int count=0;
private boolean flag = false;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what==0){
customView.setText(mList.get(count));
customView.setBackgroundColor(Color.parseColor(mList.get(count)));
if(count<mList.size()-1)
count++;
else
count=0;
handler.sendEmptyMessageDelayed(0,1000);
}
}
};
private List<String> mList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Random random=new Random();
customView = (TextView) findViewById(R.id.customView);
customView.setTextSize(30);
//初始化数据
mList = new ArrayList<>();
/*mList.add("#6187c5");
mList.add("#FFFFFF");
mList.add("#BFBFBF");
mList.add("#6699FF");
mList.add("#FF9900");
mList.add("#CC0000");*/
for(int i=0;i<50;i++){
String chars = "abcdef";
char a=chars.charAt((int)(Math.random()*6));
char b=chars.charAt((int)(Math.random()*6));
int c=random.nextInt(10);
int d=random.nextInt(10);
int e=random.nextInt(10);
int f=random.nextInt(10);
String ss="#"+a+b+c+d+e+f;
mList.add(ss);
}
customView.setText(mList.get(count));
customView.setBackgroundColor(Color.parseColor(mList.get(count)));
handler.sendEmptyMessageDelayed(0,1000);
flag=true;
customView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(flag){
flag=false;
Toast.makeText(MainActivity.this, "关闭", Toast.LENGTH_SHORT).show();
handler.removeMessages(0);
}else{
flag=true;
Toast.makeText(MainActivity.this, "开启", Toast.LENGTH_SHORT).show();
handler.sendEmptyMessageDelayed(0,1000);
}
}
});
}
by: 发表于:2017-10-13 10:10:29 顶(0) | 踩(0) 回复
??
回复评论