分享

Android开发笔记(五)— 更改手机窗口底色

 openwudi 2010-10-08

指定Layout背景最简单的方法,通常是把颜色的常数定义在darwable当中,这个范例我们要把背景变成白色。

设计思路:

  1. 在values下面新建一个color.xml,定义两个颜色,一个是白色name="white",值为#ffffffff。一个是灰色name="darkgray",值为#808080FF。
  2. 对main.xml布局文件增加两个TextView,和两个EditText。TextView使用android:textColor设置颜色为darkgray。设置全局背景android:background颜色为white。并且全局使用绝对定位。
代码如下:
EX03_02.java
package dan.ex03_02;

import android.app.Activity;
import android.os.Bundle;

public class EX03_02 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget35"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
xmlns:android="http://schemas./apk/res/android"
>
<TextView
android:id="@+id/widget28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_id"
android:textColor="@drawable/darkgray"
android:layout_x="61px"
android:layout_y="69px"
>
</TextView>
<TextView
android:id="@+id/widget29"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_psw"
android:textColor="@drawable/darkgray"
android:layout_x="61px"
android:layout_y="158px"
>
</TextView>
<EditText
android:id="@+id/widget31"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="114px"
android:layout_y="57px"
>
</EditText>
<EditText
android:id="@+id/widget30"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:textSize="18sp"
android:password="true"
android:layout_x="112px"
android:layout_y="142px"
>
</EditText>
</AbsoluteLayout>
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, EX03_02!</string>
    <string name="app_name">EX03_02</string>
    <string name="str_id">账号</string>
    <string name="str_psw">密码</string>
</resources>
color.xml
<resources>
    <drawable name="darkgray">#808080FF</drawable>
    <drawable name="white">#FFFFFFFF</drawable>
</resources>

运行效果如下:
图片

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多