Android笔记1
来源:互联网 发布:网络上的lc是什么意思 编辑:程序博客网 时间:2024/06/09 17:18
开始读《Android移动开发入门进阶》书的学习小结。
1 <Button android:text="@+id/Button01">
当新的一个button时,必须要@告诉XML解析器,解析ID字符后的部分,
当引用一个android id时,就不需要+号了,直接这样:
android:id="@android:id/Button01
代码中去获得一个button:
Button mybutton=(Button)findViewById(R.id.my_button);
2 TABLELAYOUT的例子:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView android:text="用户名:" android:textStyle="bold"
android:gravity="right" android:padding="3dip" />
<EditText android:id="@+id/username" android:padding="3dip"
android:scrollHorizontally="true" />
</TableRow>
<TableRow>
<TextView android:text="登录密码:" android:textStyle="bold"
android:gravity="right" android:padding="3dip" />
<EditText android:id="@+id/password" android:password="true"
android:padding="3dip" android:scrollHorizontally="true" />
</TableRow>
<TableRow android:gravity="right">
<Button android:id="@+id/cancel"
android:text="取消" />
<Button android:id="@+id/login"
android:text="登录" />
</TableRow>
</TableLayout>
3 relative_layout的例子
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/blue" android:padding="10dip">
<TextView android:id="@+id/label" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="请输入用户名:" />
<!--
这个EditText放置在上边id为label的TextView的下边
-->
<EditText android:id="@+id/entry" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label" />
<!--
取消按钮和容器的右边齐平,并且设置左边的边距为10dip
-->
<Button android:id="@+id/cancel" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip" android:text="取消" />
<!--
确定按钮在取消按钮的左侧,并且和取消按钮的高度齐平
-->
<Button android:id="@+id/ok" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/cancel"
android:layout_alignTop="@id/cancel" android:text="确定" />
</RelativeLayout>
4 处理用户的点击事件,这个简单
button0 = (Button) findViewById(R.id.button0);
button0.setOnClickListener(listener0);
listener0 = new OnClickListener() {
public void onClick(View v) {
Intent intent0 = new Intent(ActivityMain.this, ActivityFrameLayout.class);
setTitle("FrameLayout");
startActivity(intent0);
}
};
5 访问res/drawable目录下名叫a1的图片资源
Drawable d=this.getResources().getDrawable(R.drawable.a1);
6 MENU的操作
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, ITEM0, 0, "显示button1");
menu.add(0, ITEM1, 0, "显示button2");
menu.findItem(ITEM1);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case ITEM0:
actionClickMenuItem1();
break;
case ITEM1:
actionClickMenuItem2(); break;
}
return super.onOptionsItemSelected(item);}
7 取得前一个ACTIVETY传过来的值的方法:
Intent intent = getIntent();
String name = (String) intent.getExtras().get("name");
比如在一个文本框中输入了值NAME,点BUTTON1弹出一个对话框,把NAME值传过去,这时可以这样:
btn_dialog.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//通过Intent传递参数
Intent intent = new Intent();
intent.putExtra("name", editText.getText().toString());
//启动另一个Activity
intent.setClass(MultiActivity.this, AlertDialog.class);
startActivity(intent);
}
});
用putExtra放参数的值,用startActivety启动一个新的activety
- android学习笔记1
- Android笔记1
- Android学习笔记-1
- android 笔记 1
- Android笔记1
- 【Android笔记】(1)HelloWorld
- android学习笔记1
- android学习笔记(1)
- android 笔记1
- Android 学习笔记1
- Android 笔记1
- android学习笔记1
- android 学习笔记1
- android学习笔记(1)
- Android学习笔记1
- android基础笔记1
- Android Activity 笔记 1
- Android笔记1
- strftime()函数将时间格式化
- 利用VB远线程注入技术实现键盘拦截的例子(无DLL)
- 视频聊天服务端
- android围棋游戏开发第一周总结
- C#:DataBinding:“System.Data.DataRowView”不包含名为“id”的属性。
- Android笔记1
- 视频聊天客户端端
- 1.自动装箱和拆箱
- proxool,好东西
- flex中的动态实现remoteobject
- 什么是jiffy?
- 今天下载了王政权的《地统计学及其在生态学中的应用》,打算假期好好读读。
- 2.新的for循环
- 介绍一个不错的jquery插件-cluetip