在Android中可以自定义color资源,就像使用string资源一样,在/res/values/下面建立xml文件
格式如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#f00</color>
<color name="blue">#0000ff</color>
<color name="green">#f0f0</color>
<color name="main_back_ground_color">#ffffff00</color>
</resources>
Color Resources in Java code
int mainBackGroundColor = activity.getResources.getColor(R.color.main_back_ground_color);
Using Colors in View Definitions
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/ red"
android:text="Sample Text to Show Red Color"/>
本文介绍了如何在Android中自定义颜色资源,包括在XML文件中定义颜色值,并在Java代码和视图定义中引用这些资源。
1426

被折叠的 条评论
为什么被折叠?



