我想让文本输入布局不能被用户编辑,当用户点击它时,我想执行一个操作。我在textinputlayout的edittext中添加了android:focusable="false"
,使其不可编辑,但现在当我点击它时,它在textinputlayout的onclicklistener中不会得到回调。
<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>
发布于 2019-05-31 07:59:48
我在TextInputLayout
和TextInputEditText
上也遇到了同样的问题。我想打开一个对话框。这对我很有效
<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:
val countryChooser = view.findViewById<TextInputEditText>(R.id.country_chooser)
countryChooser.setOnClickListener { v -> showCountryDialog(v) }
发布于 2017-09-30 19:37:07
试试这段代码。打开编辑文本的clck侦听器。
<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>
发布于 2017-09-30 19:30:09
你可以试试这些
edittext.setFocusable(false);
edittext.setClickable(true);
https://stackoverflow.com/questions/46502234
复制相似问题