有没有在Android Studio的任何快捷方式得到的文本或像这样颜色的十六进制值? [英] Is there any shortcut on Android Studio to get the HEX value of color from text or something like this?

查看:239
本文介绍了有没有在Android Studio的任何快捷方式得到的文本或像这样颜色的十六进制值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望在编码过程中记住颜色codeS。是否有任何捷径获得颜色名称或其他任何获得在Android Studio中的颜色code颜色codeS?

I don't want to remember the color codes during coding. Is there is any shortcut to get the color codes from the color name or anything else to get the color code on Android Studio ?

推荐答案

您可以使用 colors.xml 您存储你的颜色。您可以稍后再访问这些XML作为 @色/ myGreen

You can use a colors.xml where you store your colors. Then you can access them later in xml as @color/myGreen.

下面是一个示例XML:

Here is a example xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="my_green">#00cc00</color>
</resources>

如果你再次需要的颜色为int你可以使用这个code:

If you need the color again as int you can use this code:

int color = context.getResources().getColor(R.color.my_green)

或者更好地避免去precated方式:

Or better to avoid deprecated methods:

Resources res = context.getResources();
int color = res.getColor(R.color.my_green, res.getTheme());

这篇关于有没有在Android Studio的任何快捷方式得到的文本或像这样颜色的十六进制值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆