android动态设置边框颜色


<?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.+'
不然会有一堆的错误


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM