Android XML通用属性

控件通用属性

<TextView/>	文本框
<Button/>	按钮
<EditText/>	可编辑文本框

XML属性说明

android:id="@+id/xxxx"

编号,自动加入R.id中

android:layout_width="match_parent"
android:layout_height="wrap_content"

设置宽度与高度

参数:

  • match_parent:随父布局变化而变化

  • wrap_content:随内容大小变化而变化

android:gravity="center"

设置对齐方式

常用参数:

  • center:垂直水平居中对齐
  • top:顶对齐
  • bottom:底对齐
  • left:左对齐
  • right:右对齐
android:textSize="xxdp"

设置字体大小,建议使用dp,因为dp不会随系统的变化而变化,稳定

android:textColor="#FFFF"

设置字体颜色

android:textAllCaps="false"

设置所有英文是否大写

android:visibility="gone"

设置控件是否可见

参数:

  • visible:可见的,默认。
  • invisible:不可见透明的,占空间。
  • gone::不可见,不占空间。

专用属性

EditText

android:hint="xxx"

设置提示字符

android:maxLines="1"

设置最大行数

android:maxLength="20"

设置最大长度(字符数)

ImageView

图片控件

android:src="@drawable/xxx"/>

设置显式图片

AlertDialog

对话框

AlertDialog

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
//标题
builder.setTitle("警告");
//内容
builder.setMessage("内存不足!");
//可否取消(back)
builder.setCancelable(false);
//确定按钮
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(MainActivity.this,"ok",Toast.LENGTH_SHORT).show();
    }
});
//取消按钮
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(MainActivity.this,"no",Toast.LENGTH_SHORT).show();
    }
});
//显示
builder.show();

ProgressDialog

进度对话框

ProgressDialog

ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
//标题
progressDialog.setTitle("警告");
//内容
progressDialog.setMessage("内存不足,正在清理内存!");
//不可取消
progressDialog.setCancelable(false);
//显示
progressDialog.show();
//延时消失
Thread t = new Thread(new Runnable() {
    @Override
    public void run() {
        try {
            //延时3秒
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //关闭
        progressDialog.dismiss();
    }
});
//启动线程
t.start();
posted @ 2020-05-14 11:16  lisztomania  阅读(293)  评论(0编辑  收藏  举报