Android基础UI编程.docx
- 文档编号:9312787
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:38
- 大小:23.17KB
Android基础UI编程.docx
《Android基础UI编程.docx》由会员分享,可在线阅读,更多相关《Android基础UI编程.docx(38页珍藏版)》请在冰豆网上搜索。
Android基础UI编程
-----------------------------------Android编程基础
1
封面
-----------------------------------Android编程基础
2
Android基础UI编程2
标题、状态栏的隐藏
标题栏隐藏
在Activity.setCurrentView();之前调用此方法
状态栏隐藏(全屏)
在Activity.setCurrentView();之前调用此方法
privatevoidHideTitle(){
//TODOAuto-generatedmethodstub
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
privatevoidHideStatusBar(){
//TODOAuto-generatedmethodstub
//隐藏标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
//定义全屏参数
intflag=WindowManager.LayoutParams.FLAG_FULLSCREEN;
//获得窗口对象
WindowmyWindow=this.getWindow();
//设置Flag标识
myWindow.setFlags(flag,flag);
}
-----------------------------------Android编程基础
3
样式化的定型对象
Style样式的定义
①新建工程
②定义一个style.xml存放样式
③在string.xml中添加字符串
④修改布局main.xml,添加两个TextView
xmlversion="1.0"encoding="utf-8"?
>
textSize">25sp textColor">#80FF00 textSize">18sp textColor">#0C688E fromAlpha">0.0 toAlpha">0.0 xmlversion="1.0"encoding="utf-8"? > 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"> 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"> -----------------------------------Android编程基础 4 ⑤加入Style ⑥结果: xmlversion="1.0"encoding="utf-8"? > xmlns: android=" android: orientation="vertical" android: layout_width="fill_parent" android: layout_height="fill_parent"> 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"> 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"> -----------------------------------Android编程基础 5 简易的按钮事件 Button事件处理 ①创建新工程 ②修改main.xml布局,添加一个TextView和一个Button ③在mainActivity.java中findViewByID()获取TextView和Button资源 ④给Button添加事件监听器Button.OnClickListener() xmlversion="1.0"encoding="utf-8"? > android=" android: orientation="vertical" android: layout_width="fill_parent" android: layout_height="fill_parent" > android: id="@+id/show_TextView" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/hello" /> xmlversion="1.0"encoding="utf-8"? > android: layout_width="fill_parent" android: layout_height="fill_parent" android: background="@color/white" xmlns: android=" >< TextView android: id="@+id/text2" android: textSize="24sp" android: layout_width="186px" android: layout_height="29px" android: layout_x="70px" android: layout_y="32px" android: textColor="@color/black" android: text="@string/layout2" > packagezyf.Ex8_UI; importandroid.app.Activity;/*import相关class*/ importandroid.os.Bundle; importandroid.view.View; importandroid.widget.Button; publicclassEx8_UIextendsActivity{ /**Calledwhentheactivityisfirstcreated.*/ @Override publicvoidonCreate(BundlesavedInstanceState){ -----------------------------------Android编程基础 9 ⑦结果 super.onCreate(savedInstanceState); /*载入main.xmlLayout*/ setContentView(R.layout.main);//默认启动布局 /*以findViewById()取得Button对象,并添加onClickListener*/ Buttonb1=(Button)findViewById(R.id.button1); b1.setOnClickListener(newButton.OnClickListener(){ publicvoidonClick(Viewv){ jumpToLayout2();//调用跳转方法jumpToLayout2() } }); }/*methodjumpToLayout2: 将 layout由 main.xml切 换 成 mylayout.xml*/ publicvoidjumpToLayout2(){ /*将layout改成mylayout.xml*/ setContentView(R.layout.mylayout); /*以findViewById()取得Button对象,并添加onClickListener*/ Buttonb2=(Button)findViewById(R.id.button2); b2.setOnClickListener(newButton.OnClickListener(){ publicvoidonClick(Viewv){ jumpToLayout1();//调用跳转方法jumpToLayout1() } }); }/*methodjumpToLayout1: 将 layout由 mylayout.xml切 换 成main.xml*/ publicvoidjumpToLayout1(){ /*将layout改成main.xml*/ setContentView(R.layout.main); /*以findViewById()取得Button对象,并添加onClickListener*/ Buttonb1=(Button)findViewById(R.id.button1); b1.setOnClickListener(newButton.OnClickListener(){ publicvoidonClick(Viewv){ jumpToLayout2();//调用跳转方法jumpToLayout2() } }); } } -----------------------------------Android编程基础 10 调用另一个Activity Intent对象的使用 ①新建工程 ②在string.xml中添加两个字符串 ③新建color.xml存放颜色值 ④修改main.xml布局,添加一个TextView和一个Button xmlversion="1.0"encoding="utf-8"? > xmlversion="1.0"encoding="utf-8"? > xmlversion="1.0"encoding="utf-8"? > android: layout_width="fill_parent" android: layout_height="fill_parent" android: background="@color/black" xmlns: android=" >< TextView android: id="@+id/text1" android: textSize="24sp" android: layout_width="186px" android: layout_height="29px" android: layout_x="70px" android: layout_y="32px" android: text="@string/act1" > xmlversion="1.0"encoding="utf-8"? > android: layout_width="fill_parent" android: layout_height="fill_parent" android: background="@color/white" xmlns: android=" >< TextView android: id="@+id/text2" android: textSize="24sp" android: layout_width="186px" android: layout_height="29px" android: layout_x="70px" android: layout_y="32px" android: textColor="@color/black" android: text="@string/act2" > packagezyf.Ex9_UI; importandroid.app.Activity; importandroid.content.Intent; importandroid.os.Bundle; importandroid.view.View; importandroid.widget.Button; publicclassSecondActivityextendsActivity{ -----------------------------------Android编程基础 12 ⑦修改mainActivity.java,添加代码 /**Calledwhentheactivityisfirstcreated.*/ @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); /*载入mylayout.xmlLayout*/ setContentView(R.layout.mylayout); /*以findViewById()取得Button对象,并添加onClickListener*/ B
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 基础 UI 编程