工作中需要依据不同的银行卡显示不同背景,由于银行很多,不可能用图片,想到了用Shape,但数量多,也不可能写死在shape的XML文件中,

<?xml version="1.0" encoding="utf-8"?>           

 最后决定用代码方式

 public static Drawable getBgDrawableByBankNo(Context ctx, String bankNo){       // int strokeWidth = 5; // 0dp 边框宽度        //int roundRadius=TypedValue.applyDimension(); // 10dp 圆角半径       // int strokeColor = Color.parseColor("#2E3135");//边框颜色        int fillColor = Color.parseColor("#971417");//内部填充颜色
        int topLeftRadius= DisplayUtil.dip2px(ctx,10);        int topRightRadius=topLeftRadius;        int bottomRightRadius=0;        int bottomLeftRadius=0;        GradientDrawable gd = new GradientDrawable();//创建drawable        gd.setGradientType(GradientDrawable.RECTANGLE);         gd.setColor(fillColor);       // gd.setCornerRadius(roundRadius);        //1、2两个参数表示左上角,3、4表示右上角,5、6表示右下角,7、8表示左下角        gd.setCornerRadii(new float[] { topLeftRadius,                topLeftRadius, topRightRadius, topRightRadius,                bottomRightRadius, bottomRightRadius, bottomLeftRadius,                bottomLeftRadius });       // gd.setStroke(strokeWidth, strokeColor);        return gd;    }

 使用

iv.setBackgroundDrawable(xxx);

 

更多相关文章

  1. Android(安卓)TextView 设置多种颜色
  2. Flutter -------- BottomNavigationBar 界面切换
  3. android Material Design Toolbar
  4. Android信息界面编辑及组合控件的封装
  5. Android:控件布局(单帧布局)FrameLayout
  6. android一个LinearLayout中具有几个控件,想要使那几个控件在Linea
  7. Android实现沉浸式(透明)状态栏适配
  8. android给图片添加边框
  9. Android电子书翻页效果实现

随机推荐

  1. Kotlin基础(一)android studio中配置Kotlin
  2. Android中数据存储----偏好设置
  3. PDF文档的读取,vudroid(Android)
  4. 深入剖析Android应用开发--视频
  5. Android(安卓)平台上的感应器开发
  6. Android鍥惧儚澶勭悊鎶€鏈紙瀹炵幇And
  7. Android Studio显示行数
  8. Android平板电脑的设计
  9. Android同一套代码打多个APP包并能够在同
  10. android调用webservice方法,参数和返回值