Android系统颜色常量 [英] Android System Color Constants

查看:82
本文介绍了Android系统颜色常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android编程使我发疯.用于GUI开发的XML或可编程方式正在使代码适得其反-有些东西在这里,有些东西在那里.

Android programming is driving me crazy. The XML or programmable ways for GUI development is making a right old dogs breakfast of the code--some stuff here, some stuff there.

我目前的不便之处在于尝试保留所有XML,我想将 TextView 的背景色设置为与 Button 的背景色相同的颜色,必须指定确切的颜色代码.我想使用系统常量,例如 java.awt.SystemColor.control ,但以XML进行指定.

My current frustration is trying to keep it all XML and I would like to set the background color of the TextView the same color as the background color of a Button without having to specify the exact color code. I would like to use a system constant, something like java.awt.SystemColor.control, but specified in XML.

是否有必要这样做而不必重新指定一堆东西?我正在寻找一种解决方案,例如: android:background ="{在此处插入常量}" .

Is there anyway of doing this without having to respecify a bunch of stuff? I'm looking for a solution like: android:background="{Insert constant here}".

推荐答案

您应该在res/values中有一个名为colors.xml的文件,它看起来应该像这样:

You should have a file in res/values called colors.xml, it should look like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="white">#FFFFFF</color>
    <color name="grey">#7A7A7A</color>
    <color name="background">#0044AA</color>
    <color name="bluelight">#449DEF</color>
    <color name="bluedark">#2F6699</color>
    <color name="greenlight">#70C656</color>
    <color name="greendark">#53933F</color>
    <color name="orangelight">#F3AE1B</color>
    <color name="orangedark">#BB6008</color>
    <color name="black">#000000</color>
</resources>

然后,您可以像这样在xml中调用颜色:

Then you can just call the color in xml like this:

android:background="@color/greenlight"

这篇关于Android系统颜色常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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