android软件开发定义颜色常数的方法--更改手机窗口画面底色

android软件开发定义颜色常数的方法--更改手机窗口画面底色

drawable 定义颜色常数的方法--更改手机窗口画面底色

①编写main布局

XML/HTML代码

1.<?xmlversion="1.0"encoding="utf-8"?>

2.<AbsoluteLayout

3.android:id="@+id/widget0"

4.android:layout_width="fill_parent"

5.android:layout_height="fill_parent"

6.xmlns:android="www.mianfeiwendang.com;

7.>

8.<TextView

9.android:id="@+id/name"

10.android:layout_width="wrap_content"

11.android:layout_height="wrap_content"

12.android:text="账号"

13.android:layout_x="61px"

14.android:layout_y="69px"

15.>

16.</TextView>

17.<TextView

18.android:id="@+id/password"

19.android:layout_width="wrap_content"

20.android:layout_height="wrap_content"

21.android:text="密码"

22.android:layout_x="61px"

23.android:layout_y="158px"

24.>

25.</TextView>

26.<EditText

27.android:id="@+id/name_in"

28.android:layout_width="120dip"

29.android:layout_height="wrap_content"

30.android:textSize="18sp"

31.android:layout_x="114px"

32.android:layout_y="57px"

33.>

34.</EditText>

35.<EditText

36.android:id="@+id/pwd_in"

37.android:layout_width="120dip"

38.android:layout_height="wrap_content"

39.android:textSize="18sp"

40.android:password="true"

41.android:layout_x="112px"

42.android:layout_y="142px"

43.>

44.</EditText>

45.</AbsoluteLayout>

②在values文件夹中定义一个drawable.xml文件 用来存放颜色值XML/HTML代码

1.<?xmlversion="1.0"encoding="utf-8"?>

2.<resources>

3.<colorname="white">#FFFFFF</color>

4.<colorname="darkgray">#938192</color>

5.<colorname="lightgreen">#7cd12e</color>

6.</resources>

③修改main.xml中的屏幕背景颜色和TextView的字体颜色XML/HTML代码

1.<AbsoluteLayout

2.android:id="@+id/widget0"

3.android:layout_width="fill_parent"

4.android:layout_height="fill_parent"

5.android:background="@color/white"

6.xmlns:android="www.mianfeiwendang.com;

7.>

8.<TextView

9.android:id="@+id/name"

10.android:layout_width="wrap_content"

11.android:layout_height="wrap_content"

12.android:text="账号"

13.android:textColor="@color/darkgray"

14.android:layout_x="61px"

15.android:layout_y="69px"

16.>

17.</TextView>

18.<TextView

19.android:id="@+id/password"

20.android:layout_width="wrap_content"

21.android:layout_height="wrap_content"

22.android:text="密码"

23.android:textColor="@color/darkgray"

24.android:layout_x="61px"

25.android:layout_y="158px"

26.>

④在mainActivity.Java代码中修改TextView背景颜色Java代码

1.publicvoidonCreate(BundlesavedInstanceState){

2.super.onCreate(savedInstanceState);

3.setContentView(R.layout.main);

4.TextViewtext=(TextView)findViewById(R.id.name);

5.//由ID获得资源

6.

7.ResourcesmyColor=getBaseContext().getResources();

8.//getBaseContext()获得基础Context

9.//getResources()获得资源

10.

11.Drawablecolor_M=myColor.getDrawable(R.color.lightgreen);

12.//由资源myColor来获得DrawableR.color.lightgreen是颜色值的ID引用13.

14.text.setBackgroundDrawable(color_M);

15.//设置背景

16.}

你可能喜欢

  • 颜色大全
  • Android开发
  • android开发教程
  • android开发环境搭建
  • android开发之旅
  • android开发设计
  • android开发工具

android软件开发定义颜色常数的方法 更改手机窗口画面底色相关文档

最新文档

返回顶部