[英]Android EditText doesn't show the Keyboard
我有一个带有三个 EditText 的屏幕,当我点击它时,屏幕顶部的第一个屏幕不会调用键盘。 我没有使用 AVD,我使用的是我自己的设备,并在其他设备上进行了测试,结果相同。
我将把屏幕和 xml 代码放在这里...... EditTexts 之间没有什么不同,只是位置。 要在该 EditText 中进行输入,我需要选择上面的 EditText 之一,然后键盘就会出现。 至少当我再次选择第一个 EditText 时它不会隐藏。 我已经尝试过 setFocus(true) 但它没有解决我的问题。 请帮我!
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SaldoCadastro" >
<TextView
android:id="@+id/tvTituloReg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Saldo Banco"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/tvErroSenha1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tvTituloReg"
android:layout_marginTop="17dp"
android:text="Insert on the field below how much you have in your bank." />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvErroSenha1"
android:layout_below="@+id/tvErroSenha1"
android:layout_marginTop="41dp"
android:text="Insert on the field below how much is your credit card limit." />
<EditText
android:id="@+id/etSaldo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tvErroSenha1"
android:ems="10"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/etCartaoLimite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:ems="10"
android:inputType="numberDecimal" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etCartaoLimite"
android:layout_below="@+id/etCartaoLimite"
android:text="About your credt card how much you've spent already." />
<EditText
android:id="@+id/etCartao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:ems="10"
android:inputType="numberDecimal" />
<Button
android:id="@+id/btRegisterSaldo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etCartao"
android:layout_below="@+id/etCartao"
android:layout_marginLeft="14dp"
android:text="Register" />
请在AndroidManifest.xml
添加属性android:windowSoftInputMode="adjustResize"
<activity
......
android:windowSoftInputMode="adjustResize">
...
</activity>
检查您的layout.xml
如果您的布局实现android:descendantFocusability="blocksDescendants"
将其删除
从 xml 中删除此行:
<requestFocus />
否则在代码中你可以添加这个:
editText.clearFocus();
嘿请检查您的AndroidManifest.xml
活动并在那里进行一些更改
android:windowSoftInputMode="stateAlwaysVisible"
在此布局示例的活动中:
<activity
android:name="com.example.a.MainActivity"
android:windowSoftInputMode="stateAlwaysVisible" // This will make your keyboard work
android:label="@string/app_name" >
你的意思是当你开始你的活动时,soft_keyboard 会出现吗?如果是这样,你只需添加以下代码:
android:windowSoftInputMode="adjustResize"
到您的AndroidManifest.xml
,例如像这样:
<activity
android:name="com.fortrun.testcrashlytics.MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
希望能帮到你!
就我而言,使用 android EditText 而不是我的自定义 EditText 解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.