效果如图:
xml文件:
maxLength:最多输入的字数;
<RelativeLayout
android:layout_marginTop="18dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edit_yjfk"
android:maxLength="200"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="26dp"
android:hint="对于我们的产品或服务,你还有什么意见吗?请告诉我们"
android:textColor="#ffc9c9c9"
android:textSize="13sp"
/>
<TextView
android:id="@+id/tex_editStatus"
android:layout_marginBottom="31dp"
android:layout_marginRight="23dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0/200"
android:textColor="#ff666666"
android:textSize="13dp"
/>
</RelativeLayout>
动态监测,见字知其意:
@BindView(R.id.tex_editStatus)
TextView texEditStatus;//动态改变文字
@BindView(R.id.edit_yjfk)
EditText editYjfk;//输入框
editYjfk.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
texEditStatus.setText(String.valueOf(s.length())+"/200");
if (s.length()>=200){
Toast.makeText(yjfkActivity.this, "上限了,亲", Toast.LENGTH_SHORT).show();
}
}
});