您的位置:首页 > 其它

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

2016-04-12 11:41 344 查看


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" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: