2017-05-04 147 views
1

我有EditText,輸入類型是textNoSuggestions。用數字鍵盤改變鍵盤的文字板

<android.support.design.widget.TextInputLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="16dp" 
        android:layout_marginRight="16dp" 
        android:layout_marginTop="5dp"> 

        <EditText 
         android:id="@+id/firstName" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:ems="10" 
         android:hint="Name" 
         android:inputType="textNoSuggestions" /> 
       </android.support.design.widget.TextInputLayout> 

我也有一個按鈕,在按鈕的onclick方法我試圖改變鍵盤的輸入type.This是源

final Button changeKeyboard = (Button) dialog.findViewById(R.id.change_keyboard); 
    changeKeyboard.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      firsName.setRawInputType(InputType.TYPE_CLASS_NUMBER); 

     } 
    }); 

它是一個可能改變在點擊按鈕時,鍵盤輸入型鍵盤顯示? 我怎麼能解決我的問題,謝謝大家

+0

這似乎是一個獨特的問題,並因此搜索後,我找不到一個類似的問題。祝你好運,找到答案。 – Vucko

回答

0

set是setTransformationMethod(),而不是setInputType()。因此,像:

firstName.setTransformationMethod(numberTransformationMethod.getInstance()); 
+0

也許你不明白我的問題。我想改變鍵盤的文本鍵盤中的按鈕點擊(當鍵盤顯示時)@jai khambhayta – BekaKK

0

在你的代碼,更改:

firsName.setRawInputType(InputType.TYPE_CLASS_NUMBER); 

這個(名字帶 「T」,在你的XML名稱):

firstName.setRawInputType(InputType.TYPE_CLASS_NUMBER); 

而且,你積極可以改變你的鍵盤調用setInputType,像這樣:firstName.setInputType(x),其中x是一個整數,可以是1(alfanumeric); 2(數字)或3(電話一樣)。

編輯:

可以隱藏你的鍵盤調用此您的活動:

public static void hideKeyboard(Activity activity) { 
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); 
    //Find the currently focused view, so we can grab the correct window token from it. 
    View view = activity.getCurrentFocus(); 
    //If no view currently has focus, create a new one, just so we can grab a window token from it 
    if (view == null) { 
     view = new View(activity); 
    } 
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
} 
+0

這很可能不是:)這是一個命名變量的錯字,它會導致如果是這樣的話,會出現編譯時錯誤。或者是一個空指針,如果ID不好。 – Vucko

+0

只有當鍵盤被隱藏時,它才能工作@statosdotcom – BekaKK

+0

因此隱藏,改變它並再次提升。 – statosdotcom

0
firsName.setInputType(InputType.TYPE_CLASS_NUMBER);