[英]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.