LinearLayout
布局为垂直布局
*/ linearLayout.setOrientation(LinearLayout. VERTICAL); /*
设置布局背景图
*/ linearLayout.setBackgroundResource(R.drawable. back); /* 加载
LinearLayout 为主屏布局,
显示
*/ setContentView(linearLayout);
8
Android 编程基础
/* 定义实例化一个 LinearLayout
布局参数
*/ linearLayouttParams = new
LinearLayout.LayoutParams(WRAP_CONTENT,WRAP_CONTENT); constructTextView();
setTextSizeOf(); setTextViewText() ; setStyleOfFont(); setFontColor();
toAddTextViewToLayout(); } public void constructTextView() { /* 实例化 TextView
对象
*
/ this bold_TV = new TextView(this this); this bold_italic_TV = new TextView(this
this); this default_TV = new TextView(this this); this default_bold_TV = new
TextView(this this); new TextView(this this italic_TV = this); new this
monospace_TV=new TextView(this this); new this normal_TV=new TextView(this this);
new this sans_serif_TV=new TextView(this this); new this serif_TV=new
TextView(this this); } public void setTextSizeOf() { // 设置绘制的文本大小,该值必须大于
0 bold_TV.setTextSize(24.0f); bold_italic_TV.setTextSize(24.0f);
default_TV.setTextSize(24.0f); default_bold_TV.setTextSize(24.0f);
italic_TV.setTextSize(24.0f); monospace_TV.setTextSize(24.0f);
normal_TV.setTextSize(24.0f); sans_serif_TV.setTextSize(24.0f);
serif_TV.setTextSize(24.0f); } public void setTextViewText() { /*
设置文本
*/
bold_TV.setText("BOLD"); bold_italic_TV.setText("BOLD_ITALIC");
default_TV.setText("DEFAULT"); default_bold_TV.setText("DEFAULT_BOLD");
italic_TV.setText("ITALIC"); monospace_TV.setText("MONOSPACE");
normal_TV.setText("NORMAL"); sans_serif_TV.setText("SANS_SERIF");
9
Android 编程基础
serif_TV.setText("SERIF"); } public void setStyleOfFont() { /*
设置字体风格
*/
null bold_TV.setTypeface(null Typeface. BOLD); null, null
bold_italic_TV.setTypeface(null Typeface. BOLD_ITALIC); null,
default_TV.setTypeface(Typeface. DEFAULT); default_bold_TV.setTypeface(Typeface.
DEFAULT_BOLD); null italic_TV.setTypeface(null Typeface. ITALIC ); null,
monospace_TV.setTypeface(Typeface. MONOSPACE ); null normal_TV.setTypeface(null
Typeface. NORMAL); null, sans_serif_TV.setTypeface(Typeface. SANS_SERIF);
serif_TV.setTypeface(Typeface. SERIF ); } public void setFontColor() { /* 设置文本颜
色
*/ bold_TV.setTextColor(Color. BLACK); bold_italic_TV.setTextColor(Color. CYAN);
default_TV.setTextColor(Color. GREEN ); default_bold_TV.setTextColor(Color.
MAGENTA); italic_TV.setTextColor(Color. RED); monospace_TV.setTextColor(Color.
WHITE); normal_TV.setTextColor(Color. YELLOW ); sans_serif_TV.setTextColor(Color.
GRAY); serif_TV.setTextColor(Color. LTGRAY); } public void toAddTextViewToLayout()
{ /* 把 TextView 加入 LinearLayout
布局中
*/ linearLayout.addView(bold_TV,
linearLayouttParams); linearLayout.addView(bold_italic_TV, linearLayouttParams);
linearLayout.addView(default_TV, linearLayouttParams);
linearLayout.addView(default_bold_TV, linearLayouttParams);
linearLayout.addView(italic_TV, linearLayouttParams);
linearLayout.addView(monospace_TV, linearLayouttParams);
linearLayout.addView(normal_TV, linearLayouttParams);
linearLayout.addView(sans_serif_TV, linearLayouttParams);
linearLayout.addView(serif_TV, linearLayouttParams); } }
10
Android 编程基础
③ 结果
11
Android
编程基础 更改手机窗口画面底色
drawable 定义颜色常数的方法
①
编写
main
布局
<?xml version="1.0" encoding="utf-8" ?> <TextView
android:id="@+id/name" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="账号" android:layout_x="61px"
android:layout_y="69px" > </TextView> <TextView android:id="@+id/password"