首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使textinputlayout不可编辑并在其上设置单击事件

使textinputlayout不可编辑并在其上设置单击事件
EN

Stack Overflow用户
提问于 2017-09-30 19:24:58
回答 7查看 9.5K关注 0票数 20

我想让文本输入布局不能被用户编辑,当用户点击它时,我想执行一个操作。我在textinputlayout的edittext中添加了android:focusable="false",使其不可编辑,但现在当我点击它时,它在textinputlayout的onclicklistener中不会得到回调。

代码语言:javascript
复制
   <android.support.design.widget.TextInputLayout
        android:id="@+id/tipVideoFilePath"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/uploadVideo"
        android:layout_toLeftOf="@+id/uploadVideo">

    <EditText
        android:id="@+id/etVideoFilePath"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="@dimen/dp5"
        android:singleLine="true"
        android:focusable="false"
        android:hint="@string/videoPath"
        android:textColor="@color/black"/>
</android.support.design.widget.TextInputLayout>
EN

回答 7

Stack Overflow用户

发布于 2019-05-31 07:59:48

我在TextInputLayoutTextInputEditText上也遇到了同样的问题。我想打开一个对话框。这对我很有效

代码语言:javascript
复制
<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/country_chooser_layout"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp">
    
    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/country_chooser"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:drawableEnd="@drawable/ic_expand_arrow"
        android:focusable="false"
        android:hint="Country"
        android:inputType="textCapWords" />
</com.google.android.material.textfield.TextInputLayout>

Kotlin:

代码语言:javascript
复制
val countryChooser = view.findViewById<TextInputEditText>(R.id.country_chooser)
countryChooser.setOnClickListener { v -> showCountryDialog(v) }
票数 13
EN

Stack Overflow用户

发布于 2017-09-30 19:37:07

试试这段代码。打开编辑文本的clck侦听器。

代码语言:javascript
复制
<android.support.design.widget.TextInputLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
        <EditText
            android:id="+id/etVideoFilePat"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:clickable="true" />
</android.support.design.widget.TextInputLayout>
票数 10
EN

Stack Overflow用户

发布于 2017-09-30 19:30:09

你可以试试这些

代码语言:javascript
复制
edittext.setFocusable(false);
edittext.setClickable(true);
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46502234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档