TextView设置随机大小和颜色

直接上代码:

String keyword = mData.get(position);

TextView view = new TextView(UIUtils.getContext());
//view.setTextColor(Color.parseColor("#FF00FF"));
view.setText(keyword);

Random random = new Random();
//随机大小, 16-25
int size = 16 + random.nextInt(10);
view.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);

//随机颜色,0-255 ->30 - 230,颜色值不能太小或太大,避免过亮或者过暗(美观
int r = 30 + random.nextInt(200);
int g = 30 + random.nextInt(200);
int b = 30 + random.nextInt(200);
view.setTextColor(Color.rgb(r, g, b));
posted @ 2017-05-23 16:19  Calo-missile  阅读(277)  评论(0编辑  收藏  举报