Android学习笔记(1)

常用控件使用方式

  1. TextView
  • android:layout_height和android:layout_width是Android控件必备的属性

    取值有:

    match_parent、fill_parent 当前控件大小和父布局大小相同

    wrap_content 当前控件大小能够包含里面的内容

  • android:gravity

    取值有:top、bottom、left、right、center等

    可以用"|"来同时指定多个值

  1. Button
  • android:textAllCaps

    系统对Button中的所有字母进行大写转换

    该属性可以设置禁用此效果

  1. EditText
  • android:hint

    设置输入框的提示信息

  • android:maxLines

    输入框的最大行数限制

    设置此属性后,当内容过多时,行数不会继续增加,但是文字会向上滚动

  1. ImageView
  • android:src

    可以用来设置图片资源

  • imageView.setImageResouce()方法可以动态改变图片资源

  1. ProgressBar
  • android:visivility 安卓控件的可见属性

    取值有:

    visible 表示控件可见(默认值)

    invisible 表示控件不可见,虽然不可见,但是仍占据位置和大小。可理解为透明状态

    gone 表示控件不可见且不占用任何位置

    setVisibility()方法可以设置控件可见性

    可传入参数为 View.VISIBLE View.INVISIBLE View.GONE

  • style 可以设置进度条的样式

  1. 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();
    
  2. ProgressDialog

    ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
    progressDialog.setTitle("This is ProgressDialog");
    progressDialog.setMessage("Loading..");
    progressDialog.setCancelable(true);
    progressDialog.show();
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容