密码:------(超过6位),确认按钮才亮


class:

private CharSequence temp;//监听前的文本  
private Button bt_affirm;//按钮     bt_affirm = (Button) findViewById(R.id.bt_affirm);

private EditText et_pwd;//密码     et_pwd = (EditText) findViewById(R.id.et_pwd);


et_pwd.addTextChangedListener( new TextWatcher() {

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
temp = s;

}

@Override
public void afterTextChanged(Editable s) {
if (temp.length() >5) {//长度大于5,改变按钮背景
bt_affirm.setBackgroundResource(R.drawable.bt_blue);
}else {
bt_affirm.setBackgroundColor(color.color_gray);
}
}
});



layout:

<EditText
            android:id="@+id/et_pwd"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="45dp"
            android:layout_marginLeft="10dp"
            android:padding="10dp"
            android:background="@null"
            android:maxLength="16"
            android:singleLine="true"
            android:password="true"
            android:hint="请输入登录密码"
            android:textSize="15sp" />

<Button
        android:id="@+id/bt_affirm"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="20dp"
        android:background="@color/color_gray"
        android:text="确认"
        android:textColor="@color/color_white"
        android:textSize="20sp" />



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值