博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java代码代替xml实现图片
阅读量:6992 次
发布时间:2019-06-27

本文共 1281 字,大约阅读时间需要 4 分钟。

1.使用StateListDrawable替换selector

public static StateListDrawable getSelector(Drawable normalDrawable, Drawable pressDrawable) {        StateListDrawable stateListDrawable = new StateListDrawable();        //给当前的颜色选择器添加选中图片指向状态,未选中图片指向状态        stateListDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, pressDrawable);        stateListDrawable.addState(new int[]{android.R.attr.state_enabled}, normalDrawable);        //设置默认状态        stateListDrawable.addState(new int[]{}, normalDrawable);        return stateListDrawable;}

默认不好使需要在使用的对象设置为可点击的;有两种方法:

方法1

tv.setClickable(true);

方法2:

tv.setOnClickListener(new View.OnClickListener() {     @Override     public void onClick(View v) {         UIUtils.toast(tv.getText().toString(),false);     } });

 

2.使用GradientDrawable替换shape

public static Drawable getDrawable(int rgb,float radius){        GradientDrawable gradientDrawable = new GradientDrawable();        gradientDrawable.setColor(rgb);  //填充颜色        gradientDrawable.setGradientType(GradientDrawable.RECTANGLE); //shape矩形        gradientDrawable.setCornerRadius(radius);  //四周圆角半径        gradientDrawable.setStroke(UIUtils.dp2px(1), rgb); //边框厚度与颜色        return gradientDrawable;}

  

转载于:https://www.cnblogs.com/ganchuanpu/p/5989154.html

你可能感兴趣的文章
(转载)JavaScript大师Nicholas C. Zakas谈TypeScript
查看>>
2011蓝桥杯(高职)
查看>>
Kraft 0.50 发布,小型文档管理程序
查看>>
Nginx 1.3.10 开发版发布
查看>>
ASP.NET控件缩写大全
查看>>
windows 2003 下IIS没有ASP.NET 1.1.4322选项卡
查看>>
TP-Link 普联 TL-PA201 及TL-PWA2801N配对配置过程
查看>>
windows phone8 相比windows phone7中不同
查看>>
DDD~基础设施层
查看>>
Struts+iBatis+Spring+mysql整合开发
查看>>
将C++里的Mat矩阵保存并由matlab提取分析
查看>>
从程序员到项目经理(14):项目经理必须懂一点“章法”
查看>>
linux系统监控示例:vmstat
查看>>
Lock关键字的用法
查看>>
Automatic Tuning of Undo Retention
查看>>
Android 程序清单文件详解
查看>>
NFS挂载文件系统:unable to get mount port number from server, using default
查看>>
Attributes
查看>>
hdu 1270
查看>>
扩展整数poj 1061 青蛙的约会 扩展欧几里得
查看>>