编写程序界面
UITestactivity
常用控件使用方法
TextView 显示文本信息
- android:singleLine 设置单行显示。
- android:lines 设置文本的行数,设置两行就显示两行,即使第二行没有数据
- android:minLines 设置文本的最小行数,与lines类似。
- android:maxLines 设置文本的最大显示行数,与width或者layout_width结合使用,超出部分自动换行,超出行数将不显示
- android:lineSpacingExtra 设置行间距。
- android:lineSpacingMultiplier 设置行间距的倍数。如”1.2”
- android:numeric 如果被设置,该TextView有一个数字输入法。此处无用,设置后唯一效果是TextView有点击效果。
- android:maxLength 限制显示的文本长度,超出部分不显示。
- android:ems 设置TextView的宽度为N个字符的宽度。这里测试为一个汉字字符宽度
- android:maxEms 设置TextView的宽度为最长为N个字符的宽度。与ems同时使用时覆盖ems选项。
- android:minEms 设置TextView的宽度为最短为N个字符的宽度。与ems同时使用时覆盖ems选项。
- android:password 以小点”.”显示文本(密码框)
- android:phoneNumber 设置为电话号码的输入方式。
- android:shadowColor 指定文本阴影的颜色,需要与shadowRadius一起使用。
- android:shadowRadius 设置阴影的半径。设置为0.1就变成字体的颜色了,一般设置为3.0的效果比较好。
- android:shadowDx 设置阴影横向坐标开始位置。
- android:shadowDy 设置阴影纵向坐标开始位置。
- android:autoLink 设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接。
- android:autoText 自动执行输入值的拼写纠正。
- android:bufferType 指定getText()文本类别(editable-调用append方法加字符,spannable 则可在给定的字符区域使用样式)。
- android:capitalize 设置英文字母大写类型。
- android:cursorVisible 光标为显示/隐藏,默认显示。
- android:visibility 控件的显示/隐藏/不可见
- android:digits 允许输入哪些字符。如“1234567890.±*/% ()”。
- android:drawable(Top/Bottom/Left/Right) 在text(上/下/左/右)添加一个drawable。
- android:drawablePadding text与drawable(图片)的间隔。
- android:editable 是否可编辑。
- android:editorExtras 设置文本的额外的输入数据。
- android:ellipsize 文字过长时,省略号显示 (start-在开头)/(end-在结尾)/(middle-在中间)/(marquee-动画横向移动);
- android:marqueeRepeatLimit 在ellipsize指定marquee的情况下,设置重复滚动的次数,marquee_forever时表示无限次
- android:scrollHorizontally 设置文本超出TextView的宽度的情况下,是否出现横拉条。
- android:freezesText 设置保存文本的内容以及光标的位置。
- android:gravity 文本位置。
- android:hintText 文字提示信息,可通过textColorHint设置提示信息的颜色。
- android:includeFontPadding 设置文本是否包含顶部和底部额外空白,默认为true。
- android:inputMethod 为文本指定输入法,需要完全限定名(完整的包名)。
- android:inputType 设置文本的类型,用于帮助输入法显示合适的键盘类型。inputType 输入法类型
- android:linksClickable 设置链接是否点击连接,即使设置了autoLink
- **android:textColor 设置文本颜色 **
- android:textColorHighlight 被选中文字的底色,默认为蓝色
- android:textColorHint 设置提示信息文字的颜色,默认为灰色。与hint一起使用。
- android:textColorLink 文字链接的颜色.
- android:textScaleX 设置文字之间间隔,默认为1.0f。
- android:textSize 设置文字大小,推荐度量单位”sp”。
- android:textStyle设置字形[bold(粗体)0, italic(斜体) 1, bolditalic(又粗又斜) 2] 可以设置一个或多个,用“|”隔开
- android:typeface 字体设置
- android:height 设置文本区域的高度,支持度量单位:px(像素)/dp/sp/in/mm(毫米)
- android:maxHeight 设置文本区域的最大高度
- android:minHeight设置文本区域的最小高度
- android:width 设置文本区域的宽度,支持度量单位:px(像素)/dp/sp/in/mm(毫米),与layout_width的区别看这里。
- android:maxWidth设置文本区域的最大宽度
- android:minWidth设置文本区域的最小宽度
- android:selectAllOnFocus 如果文本是可选择的,让他获取焦点而不是将光标移动为文本的开始位置或者末尾位置。TextView中设置后无效果。
- android:imeOptions 附加功能,设置右下角IME动作与编辑框相关的动作,如actionDone右下角将显示一个“完成”,而不设置默认是一个回车符号。
- android:imeActionId 设置IME动作ID。
- android:imeActionLabel 设置IME动作标签。
示例:
<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="24sp"
android:textColor="#00ff00"
android:text="Hello World!"
/>
简单的包括id、width、height、gravity、textsize、textcolor、text的一个文本显示
- id
- layout_width / layout_height
- match_parent:和父布局决定控件的大小
- wrap_content:由空间内容决定当前控件的大小
- gravity:top\bottom\left\right\center
- textColor:#
- textSize:sp
Button 按钮
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:textAllCaps="false"
/>
- android:textAllCaps=“false” 大小写锁定false取消
EditText 输入框
示例:
<EditText
android:id="@+id/edit_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="please"
android:maxLines="2"
/>
- 框内提示隐藏文字 / 最大行数为2
Button button = (Button)findViewById(R.id.button1);
final EditText editText = (EditText)findViewById(R.id.edit_text1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String InputText = editText.getText().toString();
Toast.makeText(MainActivity.this,InputText,Toast.LENGTH_SHORT).show();
}
});
- 调用框内文字
ImageView 展示图片
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image1"
/>
ProgressBar 进度条显示
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressbar1"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
/>
默认是圆圈的进度条
- style="?android:attr/progressBarStyleHorizontal" 转变成水平进度条
- android:max=“100” 设置进度条最大值
AlertDialog 弹出对话框
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("This is a dialog");
dialog.setMessage("Something important.");
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
dialog.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
dialog.show();
ProgressDialog 进度条对话框
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setTitle("This is a Progressdialog");
progressDialog.setMessage("Load...");
progressDialog.setCancelable(true);
progressDialog.show();
progressDialog.dismiss();
progressDialog.dismiss();数据加载结束后关闭对话框