Is there any shortcut on Android Studio to get the HEX value of color from text or something like this?

老子叫甜甜 提交于 2020-01-06 21:20:16

问题


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 ?


回答1:


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

Here is a example xml:

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

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

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

Or better to avoid deprecated methods:

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


来源:https://stackoverflow.com/questions/34436567/is-there-any-shortcut-on-android-studio-to-get-the-hex-value-of-color-from-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!