<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:color="#d6d6d6" android:width="1dp"/>//設置邊框的顏色和寬度
//設置邊框的圓角 <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp"/>
<solid android:color="#f75830" ></solid>//設置邊框的填充色
</shape>
1.動態改變邊框的顏色:
spaceTV = (TextView)findViewById(R.id.space);//spaceTV需要改變邊框的控件
GradientDrawable drawable = (GradientDrawable) spaceTV.getBackground();
drawable.setStroke(1, Color.parseColor("#ff0000"));//設置邊框的寬度和顏色
如果使用自己定義的顏色請使用drawable.setColor(getResources().getColor(R.color.yellow_color));
設置填充色
drawable.setColor( Color.parseColor("#ff495b"));
事情該步驟的前提:
compile 'com.android.support:design:25.+'
不然會有一堆的錯誤