UI控件--EditText

属性

  • 设置最大显示行数 android:maxLines
  • 设置默认显示的提示信息 android:hint
  • 设置文本框中的输入类型属性 android:inputType

关于密码显示的设置

  • 将输入的内容转换为*,变为不可辨认
        editText= (EditText) findViewById(R.id.editText);
        button= (Button) findViewById(R.id.button_pass);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editText.setTransformationMethod(new PasswordTransformationMethod());
            }
        });

这里写图片描述

  • 将密码变为可见,可以看到
  • 在布局文件中要添加代码如下
android:inputType="textPassword"
  • 代码如下
        editText= (EditText) findViewById(R.id.editText);
        button= (Button) findViewById(R.id.button_pass);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editText.setTransformationMethod(null);
            }
        });

这里写图片描述

  • 编辑带圆角和描边的EditText
  • 首先定义shape的xml文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="8dp"></corners>
    <stroke android:color="#000000"
        android:width="2dp"></stroke>
    <padding android:bottom="8dp" android:left="8dp" android:right="8dp" android:top="8dp"></padding>
</shape>
  • 然后再布局文件中进行引用
<EditText
        android:id="@+id/editText_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edittext_1"
        android:layout_margin="10dp"
        android:hint="@string/editText1"
        android:maxLines="2"
        />
  • 效果图
    这里写图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值