sunwei07

Android入门 新手学习 开发

BlogJava 首页 新随笔 联系 聚合 管理
  4 Posts :: 1 Stories :: 0 Comments :: 0 Trackbacks

1.string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, ActivityMain!</string>
<string name="app_name">ActivityMain</string>
<string name="name">账号:</string>
<string name="pass">密码:</string>
</resources>
2自定义的.drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color1">#ffffff</color>
<color name="color2">#938192</color>
<color name="color3">#7cd12e</color>
</resources>

3.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/color1">
<TextView
android:id="@+id/myTextViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name"
android:textColor="@color/color2"
android:layout_x="61px"
android:layout_y="69px"
/>
<TextView
android:id="@+id/myTextViewPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pass"
android:textColor="@color/color2"
android:layout_x="61px"
android:layout_y="158px"
/>
<EditText
android:id="@+id/myEditTextName"
android:layout_width="130dip"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="114px"
android:layout_y="57px"
/>
<EditText
android:id="@+id/myEditTextPass"
android:layout_width="130dip"
android:layout_height="wrap_content"
android:textSize="18sp"
android:password="true"
android:layout_x="112px"
android:layout_y="142px"
/>
</AbsoluteLayout>
4.ActivityMain.java


package org.Gofe.drawable;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.TextView;

public class ActivityMain extends Activity {
/** Called when the activity is first created. */
private TextView myTextViewName;
private TextView myTextViewPass;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//由ID获得对象
myTextViewName=(TextView)findViewById(R.id.myTextViewName);
myTextViewPass=(TextView)findViewById(R.id.myTextViewPass);
//getBaseContext获得基础Context,getResources获得资源
Resources myColor=getBaseContext().getResources();
  //由资源myColor获得Drawable,R.color.color3是颜色值id的引用
Drawable color_N=myColor.getDrawable(R.color.color3);
Drawable color_P=myColor.getDrawable(R.color.color3);
//设置背景
myTextViewName.setBackgroundDrawable(color_N);
myTextViewPass.setBackgroundDrawable(color_P);

}
}

posted on 2011-02-15 11:24 sunwei_07 阅读(343) 评论(0)  编辑  收藏 所属分类: Android

只有注册用户登录后才能发表评论。


网站导航: