密碼:------(超過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" />



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章