android - 无法编辑 EditText
问题描述
我遇到了一个从未遇到过的奇怪问题。
我正在为一个活动构建一个相当复杂的布局。我唯一的问题是,我无法以任何方式编辑编辑文本。我已经尝试过模拟器和真实设备。更具体地说,当我单击编辑文本时,光标会出现很短的时间,然后消失。键盘永远不会出现。在 java 代码中,我没有对 EditTexts 做任何事情(甚至还没有调用它们)。
知道可能是什么问题吗?
我已经尝试了其他帖子的许多解决方案,但没有运气。
在此处附加xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
tools:context=".Iscrizione"
android:orientation="vertical">
<ScrollView
android:id="@+id/valutazione_sv_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:descendantFocusability="blocksDescendants">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="@string/valutazione_1"
android:textAlignment="center"
android:textSize="16sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/valutazione_1_1"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/valutazione_1_2"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/valutazione_1_3"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/valutazione_1_4"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/valutazione_1_5"/>
<EditText
android:id="@+id/valutazione_et_1_5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:cursorVisible="true"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="@string/valutazione_2"
android:textAlignment="center"
android:textSize="16sp"/>
<EditText
android:id="@+id/valutazione_et_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:maxLength="2000"
android:maxLines="4"/>
<Button
android:id="@+id/valutazione_puls_prosegui1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="30dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="@color/pulsanti"
android:text="@string/pulsavanti"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
解决方案
android:descendantFocusability="blocksDescendants"
从你的删除LinearLayout
它会工作
"blocksDescendants"
ViewGroup 将阻止它的后代 | 接收焦点。
试试这个
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/valutazione_sv_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="valutazione_1"
android:textAlignment="center"
android:textSize="16sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="valutazione_1_1"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="valutazione_1_2"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="valutazione_1_3"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="valutazione_1_4"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/valutazione_cb_1_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="valutazione_1_5"/>
<EditText
android:id="@+id/valutazione_et_1_5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:cursorVisible="true"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="valutazione_2"
android:textAlignment="center"
android:textSize="16sp"/>
<EditText
android:id="@+id/valutazione_et_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:maxLength="2000"
android:maxLines="4"/>
<Button
android:id="@+id/valutazione_puls_prosegui1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="30dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:text="pulsavanti"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
推荐阅读
- jquery - jQuery 表生成器是未附加标记
- c# - 设计多个表使用相同模型的 SQL 数据库
- prolog - 检查列表的前三个元素是否是相同的数据类型。Prolog
- c++ - CGAL:为形状检测手动创建点集
- angular - 如何动态处理下面的块组件
- javascript - Promise 返回 'undefined' 或 babel 编译的代码不等待返回 (async/await)
- c# - Amadeus for Developers,不知道如何配置?
- php - 如何使用查询生成器查询数据透视表值?
- python - 从 2D 图像中查找墙壁的 Z 角位置
- javascript - 如何正确地将参数添加到本地函数?