常用控件使用方式
- TextView
-
android:layout_height和android:layout_width是Android控件必備的屬性
取值有:
match_parent漠嵌、fill_parent 當(dāng)前控件大小和父布局大小相同
wrap_content 當(dāng)前控件大小能夠包含里面的內(nèi)容
-
android:gravity
取值有:top、bottom、left、right、center等
可以用"|"來同時(shí)指定多個(gè)值
- Button
-
android:textAllCaps
系統(tǒng)對(duì)Button中的所有字母進(jìn)行大寫轉(zhuǎn)換
該屬性可以設(shè)置禁用此效果
- EditText
-
android:hint
設(shè)置輸入框的提示信息
-
android:maxLines
輸入框的最大行數(shù)限制
設(shè)置此屬性后,當(dāng)內(nèi)容過多時(shí),行數(shù)不會(huì)繼續(xù)增加柴梆,但是文字會(huì)向上滾動(dòng)
- ImageView
-
android:src
可以用來設(shè)置圖片資源
imageView.setImageResouce()方法可以動(dòng)態(tài)改變圖片資源
- ProgressBar
-
android:visivility 安卓控件的可見屬性
取值有:
visible 表示控件可見(默認(rèn)值)
invisible 表示控件不可見,雖然不可見终惑,但是仍占據(jù)位置和大小绍在。可理解為透明狀態(tài)
gone 表示控件不可見且不占用任何位置
setVisibility()方法可以設(shè)置控件可見性
可傳入?yún)?shù)為 View.VISIBLE View.INVISIBLE View.GONE
style 可以設(shè)置進(jìn)度條的樣式
-
AlertDialog 彈出對(duì)話框
該對(duì)話框?qū)⒅庙斢谒薪缑嬖刂媳⒂校軌蚱帘纹渌丶慕换ツ芰Α?/p>
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();