一,整体布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F8F8F8"
android:clipToPadding="false"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.jiangtunjf.jgapplication.Main7Activity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="请填写持卡本人银行信息"
android:textColor="@color/text_color_content"
android:textSize="13sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="持卡人姓名"
android:textColor="@color/text_color_main"
android:textSize="15sp"/>
<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="94dp"
android:layout_toLeftOf="@+id/clearName"
android:background="@null"
android:hint="请输入姓名"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/text_color_content"
android:textColorHint="@color/text_color_hint"
android:textSize="15sp"/>
<ImageView
android:id="@+id/clearName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="2dp"
android:src="@drawable/btn_close"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/line_division"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="身份证号码"
android:textColor="@color/text_color_main"
android:textSize="15sp"/>
<EditText
android:id="@+id/et_idCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="94dp"
android:layout_toLeftOf="@+id/clearIdCard"
android:background="@null"
android:digits="0123456789XYZxyz*"
android:hint="请输入身份证号码"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/text_color_content"
android:textColorHint="@color/text_color_hint"
android:textSize="15sp"/>
<ImageView
android:id="@+id/clearIdCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="2dp"
android:src="@drawable/btn_close"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="预留手机"
android:textColor="@color/text_color_main"
android:textSize="15sp"/>
<EditText
android:id="@+id/et_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="94dp"
android:layout_toLeftOf="@+id/clearPhone"
android:background="@null"
android:hint="请输入银行预留手机号码"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/text_color_content"
android:textColorHint="@color/text_color_hint"
android:textSize="15sp"/>
<ImageView
android:id="@+id/clearPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="2dp"
android:src="@drawable/btn_close"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/line_division"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="验证码"
android:textColor="@color/text_color_main"
android:textSize="15sp"/>
<EditText
android:id="@+id/et_captcha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="94dp"
android:layout_toLeftOf="@+id/clearCaptcha"
android:background="@null"
android:hint="请输入验证码"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/text_color_content"
android:textColorHint="@color/text_color_hint"
android:textSize="15sp"/>
<ImageView
android:id="@+id/clearCaptcha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/getCaptcha_line"
android:padding="2dp"
android:src="@drawable/btn_close"/>
<View
android:id="@+id/getCaptcha_line"
android:layout_width="1dp"
android:layout_height="17dp"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/getCaptcha"
android:background="@color/red_light"/>
<TextView
android:id="@+id/getCaptcha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="获取验证码"
android:textColor="@color/text_color_main"
android:textSize="15sp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
二,java 代码
private EditText mEtName;
private EditText mIdCard;
private EditText mPhone;
private EditText mCaptcha;
private ImageView clearName;
private ImageView clearIdCard;
private ImageView clearPhone;
private ImageView clearCaptcha;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main7);
mEtName = findViewById(R.id.et_name);
mIdCard = findViewById(R.id.et_idCard);
mPhone = findViewById(R.id.et_phone);
mCaptcha = findViewById(R.id.et_captcha);
clearName = findViewById(R.id.clearName);
clearIdCard = findViewById(R.id.clearIdCard);
clearPhone = findViewById(R.id.clearPhone);
clearCaptcha = findViewById(R.id.clearCaptcha);
initEvent();
RxTextView.textChanges(mEtName).subscribe(new Consumer<CharSequence>() {
@Override
public void accept(CharSequence charSequence) throws Exception {
RxView.visibility(clearName).accept(charSequence.length() > 0);
}
});
RxTextView.textChanges(mIdCard).subscribe(new Consumer<CharSequence>() {
@Override
public void accept(CharSequence charSequence) throws Exception {
RxView.visibility(clearIdCard).accept(charSequence.length() > 0);
}
});
RxTextView.textChanges(mPhone).subscribe(new Consumer<CharSequence>() {
@Override
public void accept(CharSequence charSequence) throws Exception {
RxView.visibility(clearPhone).accept(charSequence.length() > 0);
}
});
RxTextView.textChanges(mCaptcha).subscribe(new Consumer<CharSequence>() {
@Override
public void accept(CharSequence charSequence) throws Exception {
RxView.visibility(clearCaptcha).accept(charSequence.length() > 0);
}
});
}
private void initEvent() {
clearName.setOnClickListener(this);
clearIdCard.setOnClickListener(this);
clearPhone.setOnClickListener(this);
clearCaptcha.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.clearName:
mEtName.setText("");
break;
case R.id.clearIdCard:
mIdCard.setText("");
break;
case R.id.clearPhone:
mPhone.setText("");
break;
case R.id.clearCaptcha:
mCaptcha.setText("");
break;
}
}
三,效果图