2016-12-23 66 views
0

我想使用EditText作爲條形碼掃描儀的輸入。只有硬件鍵盤的Android EditText

條碼掃描器就像一個物理鍵盤。

  1. 我掃描條碼

  2. 這類型的條形碼就像一個外部鍵盤上輸入

我有一個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" 
      > 

回答

1

然後用TextChange監聽器爲您EDITTEXT。像這樣

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 
    } 
    }); 
0

請與該物業嘗試

android:inputType="none"