常用控件使用方式
- TextView
-
android:layout_height和android:layout_width是Android控件必备的属性
取值有:
match_parent、fill_parent 当前控件大小和父布局大小相同
wrap_content 当前控件大小能够包含里面的内容
-
android:gravity
取值有:top、bottom、left、right、center等
可以用"|"来同时指定多个值
- Button
-
android:textAllCaps
系统对Button中的所有字母进行大写转换
该属性可以设置禁用此效果
- EditText
-
android:hint
设置输入框的提示信息
-
android:maxLines
输入框的最大行数限制
设置此属性后,当内容过多时,行数不会继续增加,但是文字会向上滚动
- ImageView
-
android:src
可以用来设置图片资源
imageView.setImageResouce()方法可以动态改变图片资源
- ProgressBar
-
android:visivility 安卓控件的可见属性
取值有:
visible 表示控件可见(默认值)
invisible 表示控件不可见,虽然不可见,但是仍占据位置和大小。可理解为透明状态
gone 表示控件不可见且不占用任何位置
setVisibility()方法可以设置控件可见性
可传入参数为 View.VISIBLE View.INVISIBLE View.GONE
style 可以设置进度条的样式
-
AlertDialog 弹出对话框
该对话框将置顶于所有界面元素之上,能够屏蔽其他控件的交互能力。
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this); dialog.setTitle("This is Dialog"); dialog.setMessage("Something important"); dialog.setCancelable(false); dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialog.show(); -
ProgressDialog
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setTitle("This is ProgressDialog"); progressDialog.setMessage("Loading.."); progressDialog.setCancelable(true); progressDialog.show();