Android学习笔记(二) —— 更改手机窗口画面底色—color定义颜色常数的方法
2012-11-09 12:00
591 查看
窗口的底色是“深黑色”,这是SDK默认的颜色,要更改Activity里的窗口底色有许多方法,最简单的方法就是将颜色色码事先定义在color中,当程序onCreate创建的同时,加载预先定义的画面颜色。
此范例程序的设计方式是在color里指定Layout的背景(BackGround)为粉色,但这里的粉色颜色色码为#FFC0CB)预先定义在color当中,当程序运行时,背景就会变为粉色。
运行结果:
操作步骤:
step1:新建Android工程EX03_02_BackgroundColorDemo
step2:res->values下添加color.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="red">#FF0000</color>
<color name="darkgray">#A9A9A9</color>
<color name="lightskyblue">#87CEFA</color>
<color name="pink">#FFC0CB</color>
<color name="lightpink">#FFB6C1</color>
<color name="darkblue">#00008B</color>
</resources>
step3:res->values->strings.xml
<resources>
<string name="app_name">EX03_02_BackgroundColorDemo</string>
<string name="hello_world">Hello world,EX03_02_BackgroundColorDemo!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_ex03_02__background_color_demo">EX03_02_BackgroundColorDemo</string>
<string name="number">账号</string>
<string name="pwd">密码</string>
</resources>
step4:res->layout->main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/pink">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/number"
android:textColor="@color/darkblue"
android:layout_x="61px"
android:layout_y="69px"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pwd"
android:textColor="@color/darkblue"
android:layout_x="61px"
android:layout_y="158px"/>
<EditText
android:layout_width="120dip"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="114px"
android:layout_y="57px"/>
<EditText
android:layout_width="120dip"
android:layout_height="wrap_content"
android:textSize="18sp"
android:password="true"
android:layout_x="112px"
android:layout_y="142px"/>
</AbsoluteLayout>
step5:EX03_02_BackgroundColorDemo.java
package com.example.ex03_02_backgroundcolordemo;
import android.os.Bundle;
import android.app.Activity;
public class EX03_02_BackgroundColorDemo
extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
此范例程序的设计方式是在color里指定Layout的背景(BackGround)为粉色,但这里的粉色颜色色码为#FFC0CB)预先定义在color当中,当程序运行时,背景就会变为粉色。
运行结果:
操作步骤:
step1:新建Android工程EX03_02_BackgroundColorDemo
step2:res->values下添加color.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="red">#FF0000</color>
<color name="darkgray">#A9A9A9</color>
<color name="lightskyblue">#87CEFA</color>
<color name="pink">#FFC0CB</color>
<color name="lightpink">#FFB6C1</color>
<color name="darkblue">#00008B</color>
</resources>
step3:res->values->strings.xml
<resources>
<string name="app_name">EX03_02_BackgroundColorDemo</string>
<string name="hello_world">Hello world,EX03_02_BackgroundColorDemo!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_ex03_02__background_color_demo">EX03_02_BackgroundColorDemo</string>
<string name="number">账号</string>
<string name="pwd">密码</string>
</resources>
step4:res->layout->main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/pink">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/number"
android:textColor="@color/darkblue"
android:layout_x="61px"
android:layout_y="69px"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pwd"
android:textColor="@color/darkblue"
android:layout_x="61px"
android:layout_y="158px"/>
<EditText
android:layout_width="120dip"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="114px"
android:layout_y="57px"/>
<EditText
android:layout_width="120dip"
android:layout_height="wrap_content"
android:textSize="18sp"
android:password="true"
android:layout_x="112px"
android:layout_y="142px"/>
</AbsoluteLayout>
step5:EX03_02_BackgroundColorDemo.java
package com.example.ex03_02_backgroundcolordemo;
import android.os.Bundle;
import android.app.Activity;
public class EX03_02_BackgroundColorDemo
extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
相关文章推荐
- 更改手机窗口画面底色-----drawable定义颜色常数的方法
- 更改手机窗口画面底色——color.xml定义颜色
- 更改手机窗口画面底色和控件颜色
- 更改手机窗口画面底色
- 3.2 MonoForAndroid用户人机界面-更改手机窗口画面底色
- 更改手机窗口画面底色
- Android基础教程(二)之------更改手机窗口画面底色
- Android SDK 开发范例大全---3.2更改手机窗口画面底色
- Android初级教程九——更改手机窗口画面底色
- Android:认识R类、findViewById方法查找组件、@string查找字符、@color查找颜色、@drawable查找图片、@dimen某个组件尺寸定义、项目引入资源国际化
- Windows7系统更改半透明窗口颜色的方法(图文教程)
- Android学习笔记(五) —— 取得手机屏幕的大小 — DisplayMetrics取得画面宽高的方法
- 更改手机窗口的颜色
- 更改TextView文字颜色——引用color.xml中的颜色常数
- Css颜色定义的方法汇总color属性设置方式
- PB [Grid风格数据窗口改变线条颜色] 的变通实现方法(也可以成为 带表头的Grid数据窗口)
- Dreamweaver CS5更改代码颜色方法(可自定义)
- 在showModalDialog打开的画面中提交form时,不想打开新窗口的解决方法
- UIColor使用colorWithRed定义颜色
- 更改系统的窗口颜色后,网页的背景不能显示