Android中获取颜色的几种方法

2018-12-20 00:09:02

Android中获取颜色的几种方法:

通过android封装好的Color类中的常量 

public static final int BLACK = 0xFF000000;

public static final int DKGRAY = 0xFF444444;

public static final int GRAY = 0xFF888888;

public static final int LTGRAY = 0xFFCCCCCC;

public static final int WHITE = 0xFFFFFFFF;

public static final int RED = 0xFFFF0000;

public static final int GREEN = 0xFF00FF00;

public static final int BLUE = 0xFF0000FF;

public static final int YELLOW = 0xFFFFFF00;

public static final int CYAN = 0xFF00FFFF;

public static final int MAGENTA = 0xFFFF00FF;

public static final int TRANSPARENT = 0;

直接使用0x开头的颜色值,后续八位分别是透明度,ff为不透明,R,G,B值 

例如:int color = 0xff00ff00;

这是最简单的使用方法

如果知道ARGB的取值,那么可以使用Color类的静态方法argb创建一个颜色: 

int color = Color.argb(127, 255, 0, 255); // 半透明的紫色

使用xml资源文件来表示颜色 

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

<color name="colorPrimary">#3F51B5</color> 

<color name="colorPrimaryDark">#303F9F</color> 

<color name="colorAccent">#FF4081</color> 

</resources>

定义了这个颜色之后,可以使用ResourceManager类中的getColor来获取该颜色

int color = getResources().getColor(R.color.mycolor);

getResources()方法返回当前活动Activity的ResourceManager类实例。


  • 2020-12-08 08:57:12

    win10上使用win-sshfs

    首先在GitHub上下载DokanSetup-1.0.5.1000和WinSSHFS-1.6.1.13-devel 注意:Dokan不能使用最新的版本,得使用1.0.5版本。要不win-sshfs会报Dokan版本错误的问题。(win10版本)

  • 2020-12-08 11:51:54

    Ubuntu安装Node.js和npm

    Node.js是基于Chrome的JavaScript构建的跨平台JavaScript运行时环境,npm是Node.js的默认程序包管理器,也是世界上最大的软件注册表。本篇文章展示了三种在Ubuntu 20.04服务器上安装Node.js和npm的方法。

  • 2020-12-08 17:13:57

    nvm卸载、安装node和npm

    1、node.js、nvm、 npm (1)在cmd中输入`where node`找到node长须所在位置进行删除 (2)确保计算机-环境变量删除相关引用 (3)在cmd中输入`node -v` ,得到以下结果,删除成功

  • 2020-12-08 17:23:36

    Window下完全卸载删除Nodejs

    1.从卸载程序卸载程序和功能。 2.重新启动(或者您可能会从任务管理器中杀死所有与节点相关的进程)。 3.寻找这些文件夹并删除它们(及其内容)(如果还有)。根据您安装的版本,UAC设置和CPU架构,这些可能或可能不存在:

  • 2020-12-09 08:48:45

    nodejs版本以及其对应的npm版本

    正在寻找某个大版本的最新版? Node.js 10.x Node.js 8.x Node.js 6.x Node.js 4.x Node.js 0.12.x Node.js 0.10.x 所有版本

  • 2020-12-12 17:27:54

    手把手教你 GitLab 的安装及使用

    GitLab:是一个基于Git实现的在线代码仓库托管软件,你可以用gitlab自己搭建一个类似于Github一样的系统,一般用于在企业、学校等内部网络搭建git私服。