2017-05-04 148 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);