简体   繁体   English

使EditText可点击

[英]Make EditText clickable

Good evening, i have the following layout and i would like to make the Edit Text clickable everywhere. 晚上好,我的布局如下,我想使“编辑文本”在任何地方都可单击。 Also if layout_height is set to match_parent, the Edit Text clickable area works like wrap_content. 同样,如果layout_height设置为match_parent,则“编辑文本”可点击区域的工作方式类似于wrap_content。

This is the layout. 这是布局。

<?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"  
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:focusable="true"
        android:focusableInTouchMode="true">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"/>

     <RelativeLayout
         android:id="@+id/relative"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@+id/toolbar">   

    <TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:paddingRight="20dp">        

    <EditText 
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    </TextInputLayout>
    </RelativeLayout>

    <ScrollView    
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relative">

     <RelativeLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">  

    <TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginEnd="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp">     

    <EditText
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="@string/note_content"
        android:background="@null"      
        android:gravity="top"/>     

    </TextInputLayout>
    </RelativeLayout> 
    </ScrollView>

    </RelativeLayout>

How can i make the Edit Text clickable everywhere in the Relative Layout inside the Scroll View? 如何使“编辑文本”在“滚动视图”内相对布局中的任何位置都可单击?

While I don't understand why you are wanting to do this, you could make an button with the invisible property set to true, that covers the entire layout. 虽然我不明白为什么要这样做,但是您可以创建一个按钮,将invisible属性设置为true,以覆盖整个布局。 Then respond when user touches this invisible button. 然后在用户触摸此不可见按钮时做出响应。

You respond by using the EditText method called setOnEditorActionListener() 您通过使用称为setOnEditorActionListener()的EditText方法进行响应

See the info on this page with the heading "Responding to action button events": http://developer.android.com/guide/topics/ui/controls/text.html 请参阅此页面上标题为“响应动作按钮事件”的信息: http : //developer.android.com/guide/topics/ui/controls/text.html

In a scrollView you can't fill the entire view until there is content here, you are asking to make the EditText Fill the whole parent space left apart from the TextView so that you can click any part of the layout to focus on the EditText . scrollView ,直到这里有内容时,您才可以填充整个视图,您要求使EditText填充TextView之外的整个父级空间,以便您可以单击布局的任何部分以将焦点放在EditText Except you give the EditText a layout_height it will remain wrap since the layout is in the RelativeLayout' which is a child for of the ScrollView`. 除了为EditText提供layout_height ,由于布局位于RelativeLayout' which is a child for of the ScrollView RelativeLayout' which is a child for of the因此它将保持自动换行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM