【问题标题】:Prevent from changing editText on keyboard open防止在键盘打开时更改editText
【发布时间】:2017-05-12 19:06:50
【问题描述】:

在我的 Android 应用程序中,我有 ListView,标题包含 2 editText。当我尝试将注意力集中在较低的editText 上时,键盘会出现,并将焦点更改为上部的editText。标题布局xml:

<?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">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/name"
        android:hint="Title"
        android:layout_alignParentTop="true"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:nextFocusUp="@id/name"
        android:inputType="text"
        android:hint="Wordpack description"
        android:id="@+id/description"
        android:layout_below="@+id/name" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/description"
        android:inputType="text"
        android:id="@+id/locale"
        android:text="Select language"/>
</RelativeLayout>

【问题讨论】:

  • 你试过删除android:nextFocusUp标签吗?
  • @PabloBaxter 问题仍然存在

标签: android android-layout listview


【解决方案1】:

当您点击它时,似乎 ListView 正在获取焦点并将其提供给第一个孩子。看看这个answer。从它的要点来看,您需要在清单上的活动中添加以下内容:

android:windowSoftInputMode="adjustPan"

并将其添加到您的 ListView:

android:descendantFocusability="beforeDescendants"

【讨论】:

  • 这可能是次要解决方案:stackoverflow.com/questions/6918494/…
  • 使用第二种解决方案时问题仍然存在,但android:windowSoftInputMode="adjustPan 成功了。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-23
  • 1970-01-01
  • 1970-01-01
  • 2020-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多