Android学习笔记(二) —— 更改手机窗口画面底色—color定义颜色常数的方法

  窗口的底色是“深黑色”,这是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);
    }
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值