菜單
- 1選項(xiàng)菜單
app:showAsAction選項(xiàng):always
具體使用方法如下- 1 創(chuàng)建布局文件
- 2 在該布局上加載菜單
- 3 為菜單項(xiàng)注冊(cè)事件
- 2上下文菜單
上下文菜單的使用要領(lǐng)如下
(1)
(2)
(3)
OptionsMenu經(jīng)常使用的方法如下
(1)
(2)
(3)
(4)
(5)
對(duì)話框
Android中的對(duì)話框類如下所示
- 1 AlertDialog
- 2 ProgressDialog
- 3 DatePickerDialog
- 4 TimePickerDialog
裝點(diǎn)對(duì)話框
消息通知
具體步驟實(shí)現(xiàn)
- 1創(chuàng)建Notification
- 2獲取通知管理器對(duì)象
- 3創(chuàng)建Intent與PendIntent
- 4通過NotificationManager對(duì)象發(fā)出一個(gè)Notification的消息
界面優(yōu)化
LinearLayout布局(線性)
android:orientation horizontable vertical
gravity
FrameLayout(框架)
所有元素的位置都不能夠被指定
主要屬性如下
android:foreground
android:foregroundGravity
具體實(shí)現(xiàn)步驟如下:
- 1新建布局文件
- 2添加底層圖片
- 3在圖片上添加文字
RelativeLayout(相對(duì))
指定界面元素與其他元素的相對(duì)位置關(guān)系
特點(diǎn):最大程度保證在各種屏幕類型的手機(jī)上正確顯示界面布局
常用屬性如下
第一類,屬性值為true或false
第二類,屬性值必須為ID的引用名“@id/id_name”
第三類,屬性值為具體的像素值
具體實(shí)現(xiàn)步驟
- 1新建布局文件
- 2添加位于屏幕正中間的center按鈕
- 3添加位于center按鈕上方的above按鈕
- 4依次添加界面中的其余按鈕
TableLayout(表格)
TableLayout采用行、列的形式來管理組件
GrideLayout(網(wǎng)格)
默認(rèn)水平布局
GrideLayout的重要屬性有以下幾個(gè)
- 1
- 2
- 3
Activity
用于處理應(yīng)用程序的整體性工作
常用函數(shù):setContentView()、findViewById()、finish()、startActivity()
跳轉(zhuǎn) intent
- 1顯示intent
- 2隱式intent
ContextstartActivity
傳簡(jiǎn)單值方法
-
1第一個(gè)窗體:Intent攜帶值
Intent.putExtra("name","xiadong"); Intent.putExtra("age",20);
第二個(gè)Activity:SecondActivity
Intent intent=getIntent(); String first=Intent.getStringExtra("name");
-
2創(chuàng)建Bundle
Bundle bundle=Intent.getExtras(); bundle.putString("name","xiaohong"); bundle.putInt("age",20); Intent.putExtras(bundle); int age=bundle.getInt("age");
第二個(gè)Activity
Bundle bundle=Intent.getExtras(); String name=bundle.getString("name"); int age=bundle.getInt("age");
簡(jiǎn)單值傳回的方法
intent屬性
Java中的代碼
Intent it=new Intent();
it.setAction("com.example.actiomdemo.IntentTest");
startActivity(it);
配置清單AndroidMainfest.xml中的代碼
<activity
android:name="IntentTest"
android:label="">
intent構(gòu)造方法
調(diào)用本應(yīng)用中的Activity:通過串匹配的方式
調(diào)用其它應(yīng)用中的Activity:
Java中的代碼:
Intent mintent=new Intent();
ComponentName comp=new ComponentName("com.example.activitydemo","com.example.activitydemo.MainActivity");
mintent.setComponet(comp);
startActivity(mintent);
Android6.0運(yùn)行時(shí)權(quán)限機(jī)制分類。
- 1normal permission
- 2dangerous permission
Material Design
全新的設(shè)計(jì)語言,目的提供更一致、更廣泛的外觀和設(shè)計(jì),使用Material Design需要API21,即Lollipop/5.0以上
LayoutManager 布局管理器
RecyclerView使用方法
提供的三種內(nèi)置的LayoutManager:
- 1
- 2
- 3
主要的相關(guān)類
Adapter
需要實(shí)現(xiàn)的3個(gè)方法
oncreatViewHolder
onBindViewHolder
getItemCount
ViewHolder
ItemDecontion
ItemAdmin
Fragment
Android在Android3.0(API level11)中引入Fragment
優(yōu)點(diǎn)
- 1可以將activity分離成多個(gè)可重用的組件
- 2實(shí)現(xiàn)靈活的布局,改善用戶體驗(yàn),適用于不同的屏幕尺寸
- 3獨(dú)立的模塊
- 4能代替TabActivity做導(dǎo)航,并且性能更好
創(chuàng)建方法
- 1靜態(tài)
- 2動(dòng)態(tài)
常用的有如下的3個(gè)類
- 1android.app.Fragment
- 2android.app.FragmentManager
- 3android.app.FragmentTransaction(方法如下)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9