----------------------------------- Android 编程基础
1
封面
----------------------------------- Android 编程基础
2
Android
Android
Android
Android 基础 UI
UI
UI
UI 编程 2
2
2
2
标题、状态栏的隐藏
标题栏隐藏
在 Activity.setCurrentView(); 之前调用此方法
状态栏隐藏 ( 全屏 )
在 Activity.setCurrentView(); 之前调用此方法
private
private
private
private void
void
void
void HideTitle() {
// TODO
TODO
TODO
TODO Auto-generated method stub
requestWindowFeature(Window.
FEATURE_NO_TITLE
);
}
private
private
private
private void
void
void
void HideStatusBar() {
// TODO
TODO
TODO
TODO Auto-generated method stub
// 隐藏标题
requestWindowFeature(Window.
FEATURE_NO_TITLE
);
// 定义全屏参数
int
int
int
int flag=WindowManager.LayoutParams.
FLAG_FULLSCREEN
;
// 获得窗口对象
Window myWindow= this
this
this
this .getWindow();
// 设置 Flag 标识
myWindow.setFlags(flag,flag);
}
----------------------------------- Android 编程基础
3
样式化的定型对象
Style 样式的定义
①
新建工程
②
定义一个 style.xml 存放样式
③
在 string.xml 中添加字符串
④
修改布局 main.xml ,添加两个 TextView
<? xml version =
"1.0"
encoding =
"utf-8"
?>
< resources >
< style name =
"myStyle_Text1"
>
< item name =
"android:textSize"
> 25sp </ item >
< item name =
"android:textColor"
> #80FF00 </ item >
</ style >
< style name =
"myStyle_Text2"
>
< item name =
"android:textSize"
> 18sp </ item >
< item name =
"android:textColor"
> #0C688E </ item >
< item name =
"android:fromAlpha"
> 0.0 </ item >
< item name =
"android:toAlpha"
> 0.0 </ item >
</ style >
</ resources >
<? xml version =
"1.0"
encoding =
"utf-8"
?>
< resources >
< string name =
"string_A"
> 应用 myStyle_Text1 </ string >
< string name =
"string_B"
> 应用 myStyle_Text2 </ string >
</ resources >
< TextView
android:id =
"@+id/TextView01"
android:layout_height =
"wrap_content"
android:layout_width =
"fill_parent"
android:gravity =
"center_vertical|center_horizontal"
android:text =
"@string/string_A"
></ TextView >
< TextView
android:id =
"@+id/TextView02"
android:layout_height =
"wrap_content"
android:layout_width =
"fill_parent"
android:gravity =
"center_vertical|center_horizontal"
android:text =
"@string/string_B"
></ TextView >
----------------------------------- Android 编程基础
4
⑤ 加入 Style
⑥ 结果:
<? xml version =
"1.0"
encoding =
"utf-8"
?>
< LinearLayout
xmlns:android =
"http://schemas.android.com/apk/res/android"
android:orientation =
"vertical"
android:layout_width =
"fill_parent"
android:layout_height =
"fill_parent"
>
< TextView
android:id =
"@+id/TextView01"
style =
"@style/myStyle_Text1"
android:layout_height =
"wrap_content"
android:layout_width =
"fill_parent"
android:gravity =
"center_vertical|center_horizontal"
android:text =
"@string/string_A"
></ TextView >
< TextView
android:id =
"@+id/TextView02"
style =
"@style/myStyle_Text2"
android:layout_height =
"wrap_content"
android:layout_width =
"fill_parent"
android:gravity =
"center_vertical|center_horizontal"
android:text =
"@string/string_B"
></ TextView >
</ LinearLayout >
----------------------------------- Android 编程基础
5
简易的按钮事件
Button 事件处理
①
创建新工程
②
修改 main.xml 布局,添加一个 TextView 和一个 Button
③
在 mainActivity.java 中 findViewByID() 获取 TextView 和 Button 资源
④
给 Button 添加事件监听器 Button.OnClickListener()
<? xml version =
"1.0"
encoding =
"utf-8"
?>
< LinearLayout xmlns:android =
"http://schemas.android.com/apk/res/android"
android:orientation =
"vertical"
android:layout_width =
"fill_parent"
android:layout_height =
"fill_parent"
>
< TextView
android:id =
"@+id/show_TextView"
android:layout_width =
"fill_parent"
android:layout_height =
"wrap_content"
android:text =
"@string/hello"
/>
< Button
android:id =
"@+id/Click_Button"
android:layout_width =
"wrap_content"
android:layout_height =
"wrap_content"
android:text =
" 点击 "
/>
</ LinearLayout >
show = (TextView)findViewById(R.id.
show_TextView
);
press =(Button)findViewById(R.id.
Click_Button
);
press .setOnClickListener( new
new
new
new Button.OnClickListener(){
@Override
public
public
public
public void
void
void
void onClick(View v) {
// TODO
TODO
TODO
TODO Auto-generated method stub
}
});