【Android】Android常用控件的基本使用
2017-01-25 15:08
666 查看
TextView
TextView用于显示一段文本信息,如下所示:布局代码如下:
<TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#000000" android:gravity="center" android:text="TextVew" android:textColor="#00ff00" android:textSize="24sp" />
Button
Button是程序中用于和用户交互的重要控件,可以通过点击Button来触发事件:布局代码如下:
<Button android:id="@+id/Button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" android:textAllCaps="false" />
Button点击事件的监听器,见Button中的OnClickListener实现方法
EditText
EditText也是程序中和用户交互的一个重要控件,它允许用户在TextView中编辑内容,然后在程序中对这些内容进行处理:布局代码如下:
<EditText android:textColorHint="#00ffff" android:hint="Type something here" android:maxLines="3" android:id="@+id/edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" />
ImageView
ImageView用于在界面上显示图片的一个控件:布局代码如下:
<ImageView android:src="@drawable/img_1" android:id="@+id/image_view" android:layout_width="wrap_content" android:layout_height="wrap_content" />
ProgressBar
ProgressBar用于在界面上显示一个进度条,表示正在加载数据:布局代码如下:
<ProgressBar android:id="@+id/progress_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" />
AlertDialog
AlertDialog可以在当前界面上弹出一个对话框,置顶与其他界面元素之上,能够屏蔽其他控件的交互:代码如下:
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("Alert"); alert.setMessage("Something important"); alert.setCancelable(false); alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "You clicked OK", Toast.LENGTH_SHORT).show(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "You clicked cancel", Toast.LENGTH_SHORT).show(); } }); alert.show();
ProgressDialog
ProgressDialog和AlertDialog类似,能够屏蔽其他控件的交互能力,ProgressDialog还会在对话框中显示一个进度条:代码如下:
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setTitle("ProgressDialog"); progressDialog.setMessage("Loading..."); progressDialog.setCancelable(false); progressDialog.show();
相关文章推荐
- Android常用控件的基本使用说明
- [APP] Android 开发笔记 004-Android常用基本控件使用说明
- Android中常用基本控件的使用方法和步骤(.txt)
- [Android] 004_基本控件的使用_1
- android 基本控件使用
- Android基础控件之Button的基本使用
- (转)android常用控件(二) RadioGroup RadioButton CheckBox Toast的使用
- Android常用控件之ExpandableList的使用
- Android常用控件之SeekBar的使用
- Android基础控件之Button的基本使用
- Android常用控件之FragmentTabHost的使用
- android最基本的控件使用
- android应用开发笔记---常用控件使用方法
- 安卓学习基础——Android常用基本控件(一)
- Android常用控件-DatePicker以及对话框的两种使用方法
- Android中WebView控件的基本使用
- Android常用控件之RatingBar的使用
- WdatePicker 日历控件使用方法+基本常用方法
- Android常用控件之RatingBar的使用
- Android常用控件之ExpandableList的使用