And*_*per 8 android android-edittext onclicklistener android-textinputlayout
我想让用户无法编辑textinputlayout,当用户单击它时,我想执行一个操作。我android:focusable="false"在textinputlayout的edittext里面添加了使其无法编辑,但是现在当我单击它时,它在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>
Run Code Online (Sandbox Code Playgroud)
hyb*_*rid 13
我对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>
Run Code Online (Sandbox Code Playgroud)
科特林:
val countryChooser = view.findViewById<TextInputEditText>(R.id.country_chooser)
countryChooser.setOnClickListener { v -> showCountryDialog(v) }
Run Code Online (Sandbox Code Playgroud)
试试这个代码。在clck监听器上获取edittext。
<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>
Run Code Online (Sandbox Code Playgroud)
小智 5
你可以试试这些
edittext.setFocusable(false);
edittext.setClickable(true);
Run Code Online (Sandbox Code Playgroud)
设置TextInputLayout android:clickable="true"。
设置TextInputEditText android:clickable="true"和android:focusable="false"。
View.OnClickListener在TextInputLayout和上设置TextInputEditText。
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="false"/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
注意:View.OnClickListener在两个视图上都设置很重要,因为TextInputLayout大于和后面TextInputEditText。
| 归档时间: |
|
| 查看次数: |
2046 次 |
| 最近记录: |