2016年的第一个工作日啊,有些人是否在沉浸在2015年中啊!快醒醒吧!
把复杂的事情做简单了那才是王道.如图控件,界面中要使用标签来表明物品的特性.代码如下:
solid – 填充
stroke – 描边
corners – 圆角
padding – 定义内容离边界的距离。 与android:padding_left、android:padding_right这些是一个道理。
/**
* 设置标签的样式
* @param textView
* @param text
* @param bgColor
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void setTextviewStyle(TextView textView,
String text, String bgColor) {
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);//画框
//边框粗细及颜色
drawable.setStroke(5, Color.parseColor(bgColor));
drawable.setColor(
getResources().getColor(R.color.title_backgroud_color));
drawable.setCornerRadius(5);
LinearLayout.LayoutParams lp =
new LinearLayout.LayoutParams(200, 80);
textView.setTextColor(Color.parseColor(bgColor));
lp.setMargins(2, 2, 25, 2);//设置距离左上右下的距离
textView.setLayoutParams(lp);
textView.setBackground(drawable);
textView.setText(text);
textView.setGravity(Gravity.CENTER);
mLabelLly.addView(textView);
}