【问题标题】:strange: android EditText cannot show softkeyboard(it quickly hide)奇怪:android EditText 无法显示软键盘(它很快隐藏)
【发布时间】:2013-09-16 18:46:26
【问题描述】:

我有一个普通的 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

【问题讨论】:

  • 分享您的编辑文本布局代码
  • 现在有更新布局代码
  • 我尝试了您的布局,不包括 ¸`pick_school_search_view´ 以及您的颜色和图像。它工作正常,键盘在单击视图时出现,并一直保持到按下返回键。

标签: android android-edittext android-softkeyboard


【解决方案1】:

显示软键盘。你能试试这个吗。

InputMethodManager inputManager = (InputMethodManager)            
    Context.getSystemService(Context.INPUT_METHOD_SERVICE); 
    inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),      
    InputMethodManager.HIDE_NOT_ALWAYS);

您还可以添加 onEditTextFocusable() 手动强制键盘可见。

【讨论】:

  • 感谢您的回答,但我试过了,它不起作用。当 EditText 获得焦点时会显示软键盘,但它会很快消失。
  • :我曾经在windowSoftInputMode中尝试过stateVisible,但它并没有解决我的问题,它只是在活动开始时显示软键盘。
【解决方案2】:

尝试在 Manifest 文件中添加这一行

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);

【讨论】:

  • 谢谢,我试过了,但这并不能解决我的问题。我的探针是软键盘显示并很快消失。
猜你喜欢
  • 1970-01-01
  • 2021-05-22
  • 1970-01-01
  • 2011-02-17
  • 1970-01-01
  • 2012-02-18
  • 2018-01-09
  • 1970-01-01
  • 2014-08-07
相关资源
最近更新 更多