1.系统颜色

android内置的颜色,比如系统资源中定义的颜色,有以下几个:
BLACK(黑色),BLUE(蓝色),CYAN(青色),GRAY(灰色),GREEN(绿色),RED(红色),WRITE(白色),YELLOW(黄色)等
当然android的android.graphics.Color也提供了构造自定义颜色的静态方法

系统颜色的使用

①在Java代码直接设置

Button btn = (Button) findViewById(R.id.btn);
btn.setBackgroundColor(Color.BLUE);

当然你也可以获取系统颜色后再设置:

int getcolor = Resources.getSystem().getColor(android.R.color.holo_green_light);
Button btn = (Button) findViewById(R.id.btn);
btn.setBackgroundColor(getcolor);

2.自定义颜色

颜色值的定义是由透明度alphaRGB(红绿蓝)三原色来定义的, 以“#”开始,后面依次为:透明度-红-绿-蓝
eg:#RGB #ARGB #RRGGBB #AARRGGBB
而我们最常使用的就是后面两种

自定义颜色的使用:

①直接在xml文件中使用:

当然你也可以在res/values目录下,新建一个color.xml文件,为你自己指定的颜色起一个名字 这样,在需要的时候就可以根据name直接使用自定义的颜色

<!--?xml version=1.0 encoding=utf-8?-->
<resources>
<color name="mycolor">#748751</color>
</resources>

如果是直接在java代码中定义,这里要注意哦,透明度不可以省去哦!!!就像这样 0xFF080287,前面的0x代表16进制:

int mycolor = 0xff123456;
Button btn = (Button) findViewById(R.id.btn);
btn.setBackgroundColor(mycolor);

③利用静态方法argb来设置颜色:

Button btn = (Button) findViewById(R.id.btn);
btn.setBackgroundColor(Color.argb(0xff, 0x00, 0x00, 0x00));

argb()方法的参数依次为透明度,红,绿,蓝的大小,可以理解为浓度,这里组合起来的就是白色

Android中的color使用的更多相关文章

  1. Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP)

    之前的博文<Android中使用ExpandableListView实现好友分组>我简单介绍了使用ExpandableListView实现简单的好友分组功能,今天我们针对之前的所做的仿微信 ...

  2. Android中ListView实现图文并列并且自定义分割线(完善仿微信APP)

    昨天的(今天凌晨)的博文<Android中Fragment和ViewPager那点事儿>中,我们通过使用Fragment和ViewPager模仿实现了微信的布局框架.今天我们来通过使用Li ...

  3. Android中Fragment和ViewPager那点事儿(仿微信APP)

    在之前的博文<Android中使用ViewPager实现屏幕页面切换和引导页效果实现>和<Android中Fragment的两种创建方式>以及<Android中Fragm ...

  4. Android中使用ViewPager实现屏幕页面切换和页面切换效果

    之前关于如何实现屏幕页面切换,写过一篇博文<Android中使用ViewFlipper实现屏幕切换>,相比ViewFlipper,ViewPager更适用复杂的视图切换,而且Viewpag ...

  5. Android 中常见控件的介绍和使用

    1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...

  6. Android中Intent的用法总结

    Intent只在Android中特有,我把它比作一种运载工具,就像飞机一样,会把一些人带到某个地方,而且如果需要的话,还可以找到机上有哪些人员(数据),这就需要另外一些设备来支持(如:Bundle), ...

  7. Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片

    Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片 自定义ADPager 自定义水平滚动的ScrollView效仿ViewPager 当遇到要在Vie ...

  8. Android中的颜色设置

    1.在android中经常看到设置的颜色为八位的十六进制的颜色值,例如 public static final class color { public static final int lightb ...

  9. Android中View绘制流程以及invalidate()等相关方法分析

    [原文]http://blog.csdn.net/qinjuning 整个View树的绘图流程是在ViewRoot.java类的performTraversals()函数展开的,该函数做的执行过程可简 ...

随机推荐

  1. PowerDesigner最基础的使用方法入门学习(转)

    PowerDesigner最基础的使用方法入门学习   1:入门级使用PowerDesigner软件创建数据库(直接上图怎么创建,其他的概念知识可自行学习) 我的PowerDesigner版本是16. ...

  2. (转)inspect — Inspect live objects

    原文:https://docs.python.org/3/library/inspect.html 中文:https://www.rddoc.com/doc/Python/3.6.0/zh/libra ...

  3. @JsonView注解的使用

    看到一个新的注解以前没有用过,记录一下使用方法. 注意是:com.fasterxml.jackson.annotation.JsonView @JsonView可以过滤pojo的属性,使Control ...

  4. ElasticSearch Aggs的一些使用方法

    这段代码是关于多层聚合和嵌套域的聚合,来源:https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/e ...

  5. Exception message: /bin/bash: line 0: fg: no job control

    这个错误是 我本地idea 远程调试hadoop集群出现的 Diagnostics: Exception from container-launch. Container id: container_ ...

  6. java.io.IOException: Could not find status of job:job_1534233312603_0002

    hive执行插入数据操作 报错: 在hive console里面输入: set  hive.jobname.length=20; 再次执行好了:

  7. 【链表】Odd Even Linked List

    题目: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note ...

  8. 【数组】Missing Number

    题目: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is mi ...

  9. jetbrains golang IDE

    非常好的IDE,叫goland. 支持最新的golang1.8了 下载地址: https://www.jetbrains.com/go/ 开始使用手册: https://www.jetbrains.c ...

  10. 18个HTML5和JavaScript游戏引擎库

    1) Best HTML5 and javascript game engine Library-  Impactjs     2) Best HTML5 and javascript game en ...