我使用editext进行聊天。一切顺利。但是当我输入单引号时,它会显示' s'当我输入双引号时,它会显示" s"所以我想限制这两个字符。
<EditText
android:id="@+id/editText_add_chat_afcdl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="13dp"
android:textColor="@android:color/black"
android:inputType="textMultiLine"
android:maxLength="256"
android:textSize="18sp"
android:maxLines="5"
android:layout_centerVertical="true"
android:hint="@string/chatMsgHint"
android:textColorHint="#C3C3C8"
android:layout_toLeftOf="@+id/button_add_afcdl"
android:background="@drawable/rounded_edittext" />
答案 0 :(得分:2)
使用自定义输入过滤器,然后将其设置为editText。
InputFilter filter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
char[] chars = {'\'','"'};
for (int i = start; i < end; i++) {
if (new String(chars).contains(String.valueOf(source.charAt(index))) {
return "";
}
}
return null;
}
};
edit.setFilters(new InputFilter[] { filter });
答案 1 :(得分:2)
避免在代码
之后使用双引号和单引号 <input type="number" class="form-control form-control-lg" limit-to="6"
ng-model="vm.details.m_inputSMS" placeholder = {{vm.configProprs.kodPlaceHolder}} name ="m_inputSMS" id="m_inputSMS"
ng-model-options="{ updateOn: 'blur' }"required/>
您可以将滤镜设置为您的编辑文字,如下所示
public static InputFilter filter = new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned destination, int dstart, int dend) {
String blockCharacterSet = "'\"";
if (source != null && blockCharacterSet.contains(("" + source))) {
return "";
}
return null;
}
};