android 学习
*******************************
1.findViewById null错误
____________________________________________
1. if you use xml based layout, you must add this line before run findViewById.
setContentView(R.layout.main);
2. the id that you can use is only the id that define on your layout for each activity. To check the id you can
find it on R class
3. remember to use complete android:id to define an id to a view
2.menu (android.view.Menu)
______________________________________________
1. add(groupid,id,orderid,charsequence)
3.onOptionsItemSelected(MenuItem item) 和 onCreateOptionsMenu(Menu menu)对应
______________________________________________
menu.add();
MenuItem item是menu 里add进去的
4.alertDialog 弹出框
______________________________________________
new AlertDialog.Builder(this)
.setMessage(R.string.msg_dialog)
.setTitle(R.string.promote_dialog)
.setIcon(R.drawable.icon)
.setNeutralButton("Close",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dlg,int sumthin){
}
})
.show();
5
______________________________________________
options menu就是通过按home键来显示,context menu需要在view上按上2s后显示。这两种menu都有可以加入子菜单,子菜单不能
种不能嵌套子菜单。options menu最多只能在屏幕最下面显示6个菜单选项,称为icon menu,icon menu不能有checkable选项。多
于6的菜单项会以more icon menu来调出,称为expanded menu。options menu通过activity的onCreateOptionsMenu来生成,这个函
数只会在menu第一次生成时调用。任何想改变options menu的想法只能在onPrepareOptionsMenu来实现,这个函数会在menu显示前
调用。onOptionsItemSelected 用来处理选中的菜单项。
context menu是跟某个具体的view绑定在一起,在activity种用registerForContextMenu来为某个view注册context menu。context
menu在显示前都会调用onCreateContextMenu来生成menu。onContextItemSelected用来处理选中的菜单项。
6 Intent
______________________________________________
Intent intent=new Intent(Intent.ACTION_DIAL);
//intent.setClassName("com.demo", "com.demo.TestActivity");
startActivity(intent);
以上实例化一个intent 然后在AndroidManifest.xml中指定接收者,也就是多个action
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DIAL" />
<activity android:name=".SimpleIntentTest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" /><!--指定接受者1-->
<action android:name="android.intent.action.DIAL" /><!--指定接受者2-->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android学习零碎笔记
最新推荐文章于 2024-07-15 23:09:31 发布