开始读《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

更多相关文章

  1. 通过xml布局文件实现按钮改变焦点设置背景图片
  2. Android(安卓)UI开发第二十八篇――Fragment中使用左右滑动菜单
  3. android 按钮水波纹效果【背景色】
  4. Android笔记1
  5. Android笔记1
  6. 系出名门Android(5) - 控件(View)之TextView, Button, ImageButt
  7. Android的webView和h5+js交互
  8. Android(安卓)UI学习系列
  9. Android(安卓)Popuwindow使用

随机推荐

  1. Android JNI编程内存问题定位方法
  2. ubuntu 64位 无法安装android SDK解决办
  3. Android仿人人客户端(v5.7.1)——欢迎和导
  4. android phone电话调用流程
  5. android 将时长毫秒转化为分钟和秒
  6. android binder机制之二 Service Manager
  7. [Android基础]四大组件之ContentProvider
  8. Android中onConfigurationChanged监视系
  9. Android Sqlite数据库跨版本升级 保存之
  10. Android监听系统通知