2017-12-02 46 views
1

我有一個應用程序,它將meters轉換爲centimeters,簡單,對不對?禁用多個edittexts鍵盤

所以我有兩個部分。一個是鍵盤,另一個是兩個edittext盒子。

我正在使用我自己的鍵盤,所以沒有安卓鍵盤顯示的感覺。

我看了各種答案,他們似乎並沒有爲我工作。

This問題問同樣的事情,我實現了選定的答案,但edittexts行爲怪異。

enter image description here

首先一個似乎工作,因爲我想它的工作,但不知其他文本不會來的焦點。

我嘗試點擊它並沒有任何反應。重點不會從第一個開始。

我試圖

findViewById(R.id.lengthConverterSecond).setOnTouchListener(this); 
    findViewById(R.id.lengthConverterFirst).setOnTouchListener(this); 
@Override 
    public boolean onTouch(View view, MotionEvent motionEvent) { 
     return true; 
    } 

什麼了這個怪異的行爲?

什麼是解決我的上述問題?

更新

試過這種tooo。

萬一

findViewById(R.id.lengthConverterSecond).setOnFocusChangeListener(this);   findViewById(R.id.lengthConverterFirst).setOnFocusChangeListener(this); 
    @Override 
     public void onFocusChange(View view, boolean b) { 
      if(b){ 
       InputMethodManager im=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
       assert im != null; 
       im.hideSoftInputFromWindow(view.getWindowToken(),0); 
      } 
     } 

這並不在所有的工作,就像它不會隱藏鍵盤但怪異的行爲我上面看到,現在不發生。

回答

3

爲minSdk = 8,maxSdk = 23

<EditText 
    android:id="@+id/editText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:focusable="false" 
    android:focusableInTouchMode="false"/> 

的API 21或者如果你有兩個編輯文本(假設editText1和editText2)> 21

,並要使用自己的自定義鍵盤然後使用此解決方案。

EditText editText1 = findViewById(R.id.editText1); 
EditText editText2 = findViewById(R.id.editText2); 

editText1.setShowSoftInputOnFocus(false); // add this if you dont want default keyboard when you tap on editText1. 

editText2.setShowSoftInputOnFocus(false);// add this if you dont want default keyboard when you tap on editText2. 

這裏

+0

以下API級21不會工作,我的是16(分鐘) –

+0

加入用於minSdk = 8和maxSdk = 23太勾選更新的代碼 – Thunder

+0

'公共布爾onTouch(查看圖,MotionEvent motionEvent ){ switch(view.getId()){case} R.id.lengthConverterFirst:{ view.requestFocus(); } case R.id.lengthConverterSecond:{ view.requestFocus(); } } return true; } –