当前位置: 移动技术网 > 移动技术>移动开发>Android > Android 常用控件之TextView与EditText

Android 常用控件之TextView与EditText

2020年07月23日  | 移动技术网移动技术  | 我要评论

Android 常用控件之TextView与EditText

1.相关设计

  1. 本次实验新建一个相对布局LinearLayout,对其进行统一的背景颜色和方向等设置。
    实验代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#288FFFEE"
    tools:context=".MainActivity">
</LinearLayout>
  1. 对TextView的属性text文本@string/str1和textSize字号进行练习:
    实验代码:
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/str1"
    android:textSize="36sp"
    />
  1. 对TextView的属性textColor文本颜色进行练习:
    实验代码:
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/str1"
    android:textSize="36sp"
    android:textColor="@color/colorPrimary"
    />
  1. 对TextView的属性autoLink文本链接方式进行练习:
    实验代码:
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="https://www.baidu.com"
    android:autoLink="web"
    />
  1. 对TextView的属性LinksClickable、minLine和maxLine进行练习:
    实验代码:
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Baidu网址:             https://www.baidu.com"
    android:textSize="24dp"
    android:autoLink="web"
    android:linksClickable="false"
    android:minLines="2"
    android:maxLines="3"
    />
  1. 对TextView的属性singleLine和ellipsize省略位置进行练习:
    实验代码:
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="  百度(纳斯达克:BIDU)是全球最大的中文搜索引擎,中国最大的以信息和知识为核心的互联网综合服务公司,全球领先的人工智能平台型公司。"
    android:singleLine="true"
    android:ellipsize="middle"
    android:textSize="18dp"
    />
  1. 对TextView的属性marquee走马灯进行练习:
    实验代码:
<TextView
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Baidu 百度"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:textSize="36dp"
    android:textColor="@color/colorPrimary"
    />

(2)EditView用法:

  1. 对EditText的属性text输入文本和maxLength最大输入长度进行练习:
    实验代码:
<EditText
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Baidu百度"
 android:maxLength="5"
 />
  1. 对EditText的属性hint提示信息进行练习:
    实验代码:
<EditText
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:hint="搜索或输入网址"
 />
  1. 对EditText的属性selectAllOnFocus进行练习:
    实验代码:
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:selectAllOnFocus="true"
    android:text="http://www."
    />
  1. 对EditText的属性inputType软键盘类型进行练习:
    实验代码:
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="phone"
    />
  1. 对EditText的属性digits允许输入字符进行练习:
    实验代码:
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:digits="1234567890abc"
    />
  1. 对EditText的属性drawableLeft、drawablePadding和editable进行练习:
    实验代码:
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@mipmap/ic_l1"
    android:drawablePadding="10dp"
    android:editable="false"
    />

运行截图:

  1. 对EditText的属性imeOptions进行练习:
    实验代码:
<EditText
    android:id="@+id/e_username"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName"
    android:textSize="20sp"
    android:imeOptions="actionNext"
    android:hint="QQ号/手机号/邮箱"/>

<EditText
    android:id="@+id/password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="numberPassword"
    android:textSize="20sp"
    android:imeOptions="actionDone"
    android:hint="输入密码"/>

效果图

在这里插入图片描述

本文地址:https://blog.csdn.net/weixin_43362360/article/details/107470597

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网