Android, 基本控件的使用

来源:互联网 发布:妩媚的女生 知乎 编辑:程序博客网 时间:2024/05/19 06:49


1. <TextView 用于在界面上显示一段文字。。
        android:id="@+id/text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="24sp"
        android:textColor="#00ff00"
        android:text="This is TextView" />
2.<Button 设置一个按钮。。。
   android:id="@+id/button"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="Button"/>
3.<EditText 允许用户在控件里输入和编辑内容。。。
   android:id="@+id/edit_text"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:hint="Type something here"
   android:maxLines="2"
   />
4.<ImageView 用于在界面上展示图片的一个控件。。。
   android:id="@+id/image_view"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/ic_launcher"
   />
5.<ProgressBar 用于在界面上显示一个进度条,表明我们的程序正在加载。。
   android:id="@+id/progress_bar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   style="?android:attr/progressBarStyleHorizontal"
   android:max="100"
/>

6.AlertDialog可以在当前窗口弹出一个对话框,这个对话框是置顶于所有界面元素之上的,能够屏蔽掉其他控件的交互能力,一般用于提示一些非常重要的内容或者警告内容。。。

public void onClick(View v){

AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);

        dialog.setTitle("This is a Dialog");
        dialog.setMessage("Something important.");
        dialog.setCancelable(false);
        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

}
});
        dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

}
});
        dialog.show();
7.ProgressDialog与AlertDialog类似,但会在对话框中显示一个进度条。。
public void onClick(View v){
        ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
        progressDialog.setTitle("This is ProgressDialog");
        progressDialog.setMessage("Loading...");
        progressDialog.setCancelable(true);
        progressDialog.show();
0 0
原创粉丝点击