在android上使用rgb的背景颜色(XML首选)?

时间:2016-11-09 04:59:16

标签: android xml android-layout colors

这很愚蠢,但是如何在android上添加背景rgb?

我正在尝试使用RGB颜色的背景,但我找不到该怎么做。

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background= ?
android:orientation="vertical" >

我这样做了,但不起作用

Color.rgb(200,0,0)

3 个答案:

答案 0 :(得分:4)

您可以在Android中使用十六进制代码设置RGB颜色,例如Hex Code #RRGGBB

以下是一些示例颜色:

Color   Hex RGB  Decimal Code
White   #FFFFFF (255,255,255)
Red     #FF0000 (255,0,0)
Lime    #00FF00 (0,255,0)
Blue    #0000FF (0,0,255)

例如,您想在视图背景中设置蓝色

android:background= "#0000FF"

最好在Color res文件夹中定义颜色

答案 1 :(得分:2)

不确定是否可以使用XML中的RGB值。但我很确定你可以用Java做到这一点。创建组件的实例并使用方法setBackgroundColor()。使用如下:

yourComponent.setBackgroundColor(Color.rgb(200, 00, 00));

答案 2 :(得分:0)

应该是

View.setBackgroundColor(rgb(255,0,0))

您可能会收到错误导入

import android.graphics.Color.rgb