Android 如何使已禁用编辑文本和按钮的版面可单击
我有一个简单的布局和编辑文本和一个按钮Android 如何使已禁用编辑文本和按钮的版面可单击,android,Android,我有一个简单的布局和编辑文本和一个按钮 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="match_p
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clickable="true"
android:focusable="true">
<EditText
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:focusable="false"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
但它不起作用,我的意思是,当我点击时没有Toast消息。正如@Liem Vo在评论中所说:你应该在按钮中添加
android:clickable=“false”
,并且确保不要在java中添加click listener。
因为事件由子视图处理
对于“编辑文本”,您可以手动调用家长单击侦听器:
editText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View parent = (View) v.getParent();
parent.performClick();
}
});
请参考此问题:什么“不起作用”?我单击时没有祝酒词。请发布更多您的课堂内容。您是否正在扩大此布局?您是单击按钮还是布局?您可以向按钮
android:clickable=“false”
添加一个属性并检查结果
editText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View parent = (View) v.getParent();
parent.performClick();
}
});