控件依赖版本至少25
implementation 'com.android.support:design:25.+'
新建shape_radius2_border1_gray.xml文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 主体背景颜色值 -->
<solid android:color="#FFFFFF" />
<corners android:radius="2dp"></corners>
<!-- 连框宽度和颜色值 -->
<stroke
android:width="1dp"
android:color="#E9E9E9" />
</shape>
// 然后设置
android:background="@drawable/shape_radius2_border1_gray"
重点来了
LinearLayout ll_root=helper.getView(R.id.ll_root);
GradientDrawable drawable = (GradientDrawable) ll_root.getBackground();
// 设置边框的宽度和颜色
drawable.setStroke(1, Color.parseColor("#ff0000"));
网友评论