[英]strange: android EditText cannot show softkeyboard(it quickly hide)
我有一個普通的EditText視圖,單擊該視圖后會顯示軟鍵盤,但奇怪的問題是它的隱藏速度很快。 布局代碼:僅此而已
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/pick_school_bitmap_bg"
>
<LinearLayout
android:id="@+id/customer_action_bar"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/bg_action_bar_repeat"
android:orientation="horizontal"
>
<Button
android:id="@+id/home"
android:layout_width="48dp"
android:layout_height="match_parent"
android:background="@drawable/pick_school_item_background"
android:drawableLeft="@drawable/home_as_up_indicator"
android:drawableRight="@drawable/pick_school_ic_menu_search"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp" />
<EditText
android:id="@+id/input_search_school"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/pick_school_textfield_activated"
android:hint="@string/pick_school_search_hint"
android:imeOptions="actionSearch"
android:inputType="text"
android:singleLine="true"
android:textColor="@color/white"
android:textColorHint="@color/white"
/>
</LinearLayout>
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/customer_action_bar"
layout="@layout/pick_school_search_view" />
</RelativeLayout>
太奇怪了,軟鍵盤顯示並迅速消失:日志信息是:
09-16 17:55:08.472:D / InputMethodManager(31721):onInputShownChanged:true
09-16 17:55:08.527:D / InputMethodManager(31721):onInputShownChanged:false
09-16 17:55:09.282:D / InputMethodManager(31721):onInputShownChanged:true
09-16 17:55:09.322:D / InputMethodManager(31721):onInputShownChanged:false
09-16 17:55:09.522:D / InputMethodManager(31721):onInputShownChanged:true
顯示軟鍵盤。 可以請您嘗試一下。
InputMethodManager inputManager = (InputMethodManager)
Context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
您可以手動添加onEditTextFocusable()的另一件事來強制鍵盤可見。
嘗試在清單文件中添加此行
android:windowSoftInputMode="stateAlwaysHidden|adjustResize|adjustPan"
將焦點設置為edittext,以便彈出鍵盤
<EditText
android:id="@+id/idEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:inputType="textCapCharacters"
android:paddingLeft="20dp"
android:textSize="24sp" >
<requestFocus />
</EditText>
嘗試用Java代碼
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(edittext, 0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.