Android的布局元素设置背景颜色

问题描述:

我想,有些克隆的活动from一组在Android的UI设计的幻灯片。但是我有一个非常简单的任务的一个问题。

I am trying to, somewhat clone the design of an activity from a set of slides on Android UI design. However I am having a problem with a very simple task.

我已经创建了布局,显示的图像,以及标题是的TextView RelativeLayout的。现在我想更改 RelativeLayout的的背景颜色,但我似乎无法弄清楚如何。

I have created the layout as shown in the image, and the header is a TextView in a RelativeLayout. Now I wish to change the background colour of the RelativeLayout, however I cannot seem to figure out how.

我知道我可以设置安卓背景属性在XML文件中的 RelativeLayout的标签,但什么我将它设置为?我想定义一个新的颜色,我可以在多个地方使用。它是一个绘制字符串

I know I can set the android:background property in the RelativeLayout tag in the XML file, but what do I set it to? I want to define a new colour that I can use in multiple places. Is it a drawable or a string?

此外我希望那里是一个非常简单的方法来此从Eclipse的Andr​​oid UI设计师,我必须失去了在?

Additionally I would expect there to be a very simple way to this from within the Eclipse Android UI designer that I must be missing?

目前我沮丧了一下,因为这应该是与点击几下最大执行的活动。因此,任何帮助pciated非常AP $ P $。 :)

I am a bit frustrated currently, as this should be an activity that is performed with a few clicks at maximum. So any help is very appreciated. :)

您可以使用简单的颜色资源,里面的 RES /价值/ colors.xml通常指定

<color name="red">#ffff0000</color>

和通过用这个机器人:背景=@色/红色。这种颜色可以使用任何其他地方也一样,例如作为文本的颜色。在XML参考用同样的方式,或通过 getResources得到它在code()。的getColor(R.color.red)

and use this via android:background="@color/red". This color can be used anywhere else too, e.g. as a text color. Reference it in XML the same way, or get it in code via getResources().getColor(R.color.red).

您也可以使用任何绘制资源为背景,用机器人:背景=@可绘制/ mydrawable这个(这意味着9patch可绘,正常位图,形状可绘制。)

You can also use any drawable resource as a background, use android:background="@drawable/mydrawable" for this (that means 9patch drawables, normal bitmaps, shape drawables, ..).