[英]Android EditText with hardware keyboard only
I want to use an EditText for the input from Barcode Scanners. 我想使用EditText作为条形码扫描仪的输入。
The Barcode Scanner acts like a physical Keyboard. 条形码扫描仪的行为类似于物理键盘。
I scan a Barcode 我扫描条形码
It types the Barcode like an external Keyboard with a enter at the end 它像外部键盘一样键入条形码,并在末尾输入一个
I have an EditText which should always be focused but never show the software keyboard. 我有一个EditText,应该始终将其聚焦,但不要显示软件键盘。 I don't want to deactivate the Keyboard completely because it's needed in the same Class on a different EditText.
我不想完全停用键盘,因为同一类在不同的EditText上需要它。
<EditText
android:id="@+id/barcodeText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:ems="10"
android:singleLine="true"
android:cursorVisible="false"
android:gravity="center"
android:background="#00000000"
android:textColor="@color/secondary_text"
>
then use TextChange Listener for your Edittext. 然后将TextChange Listener用于您的Edittext。 Like this
像这样
editText.setInputType(InputType.TYPE_NULL);
editText.requestFocus();
editText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
if(s.length() != 0)
// Your action
}
});
请尝试此属性
android:inputType="none"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.