简体   繁体   English

即使我将inputType设置为数字edittext android,也会出现文本键盘

[英]text keyboard appear even if I have set inputType to number edittext android

I want to display the number keyboard. 我想显示数字键盘。

Here is my code to do that. 这是我的代码。 (This is an item of my list). (这是我的清单中的一项)。

       <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"   
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/checked_list_item_text"
        android:layout_width="500dp"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/checked_list_item_quatity"        
        android:layout_centerVertical="true"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/checked_list_item_quatity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="7dp"
        android:gravity="center_vertical"
        android:hint="Quantité"
        android:focusableInTouchMode="true"
        android:inputType="number"
        android:maxLength="6"
        android:textSize="30sp" />

</RelativeLayout>

When I click on edittext, the keyboard displays the numbers but switches quickly to text and I have to click a second time to get the number keyboard. 当我单击edittext时,键盘会显示数字,但会迅速切换为文本,因此我不得不再次单击以获取数字键盘。

This issue occurs only the first time when I open the activity. 仅当我打开活动时才出现此问题。

Try changing the input mode in your AndroidManifest.xml 尝试在您的AndroidManifest.xml中更改输入模式

I had the same issue when trying to get focus to an edittext field thats inside a listview. 尝试将焦点移到listview内的edittext字段时,我遇到了同样的问题。 Adding android:windowSoftInputMode="adjustPan" in the activity holding the listview solved the problem for me. 在举行列表视图的活动中添加android:windowSoftInputMode =“ adjustPan”为我解决了这个问题。

<activity android:name=".MyEditTextInListView"
           android:label="@string/app_name"
           android:windowSoftInputMode="adjustPan">

What you have should work , but it could be something on the code side. 您所拥有的应该可以工作,但是可能在代码方面。 Maybe you can force it programmatically: 也许您可以通过编程方式强制执行:

EditText checkedInput = (EditText) findViewById(R.id.checked_list_item_quatity);
checkedInput.setInputType(InputType.TYPE_CLASS_NUMBER);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM