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_颜色大全4页
- 无机化合物颜色大全4页
- 颜色大全10页
- Android颜色大全4页
- 英语颜色大全6页
- 颜色对照表大全9页
- Google+Android开发入门指南(第一版)94页
- 快速离线安装配置Android 开发环境(已多次亲测)19页
- Android开发:从环境搭建到第一个程序测试(超详细)7页
- Android开发例子15页
- Android应用开发入门与实战32页
- Android开发操作SDcard的方法2页
- android自制开发rom教程5页
- android开发动画入门教程9页
- android开发入门教程9页
- android RSS开发教程30页
- android开发教程04_3_可绘制内容和动画34页
- android开发教程04_2_OpenGL3D图形接口的使用25页
- android开发环境搭建以及配置方法7页
- android开发环境搭建8页
- VirtualBox虚拟机和android3.2搭建高效android开发环境16页
- android开发环境的搭建17页
- ubuntu11.10系统搭建android开发环境4页
- android和web开发环境搭建17页
- 14、Android 开发之旅:短信的收发及在android模拟器之间实践(一)29页
- Android开发之旅_03_android架构4页
- Android 开发之旅:短信的收发及在android模拟器之间实践(一)11页
- android Intent开发之旅22页
- android开发之旅1711页
- android开发之旅1510页


