18.Android 颜色工具类ColorUtil
2015-09-29 11:21
627 查看
18.Android 颜色工具类ColorUtil
public class ColorUtil { /** * 根据颜色资源Id,取得颜色 * * @param colorId * @return color */ public static int getResourcesColor(Context context, int colorId) { int color = 0x00ffffff; try { color = context.getResources().getColor(colorId); } catch (Exception e) { e.printStackTrace(); } return color; } /** * 将十六进制 颜色代码 转换为 int * * @return color */ public static int HextoColor(String color) { // #00000000 - #ffffffff String reg = "#[a-f0-9A-F]{8}"; if (!Pattern.matches(reg, color)) { color = "#ffffffff"; } return Color.parseColor(color); } /** * 设置颜色透明度 * * @param color * @param alpha * @return color */ public static int setColorAlpha(int color, int alpha) { int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.argb(alpha, red, green, blue); } }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件