我有不同的表格行,每一行都包含一些信息文本,这些文本不应该是可点击和不可选择的。但是当我在模拟器中运行它时,文本总是可点击的。
这意味着,当我点击任何文本 block 时,它的颜色会变为深灰色。我不希望它改变。我希望它什么都不做。
当然,我可以将深灰色设置为文本颜色,这样用户就不会看到他点击了任何东西,但这不是我想要的。
我已经尝试了不同的属性,如您在示例中所见,但没有任何帮助。此外,我实际上必须设置不可点击的是 TableRow 还是 TableRow 中的 TextView?
这是一个例子:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<TableLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:stretchColumns="*"
android:clickable="false">
<TableRow
android:layout_width="fill_parent"
android:background="#777777"
android:clickable="false">
<TextView
android:id="@+id/heading"
android:text="This is the cool heading"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:textSize="14sp"
android:paddingLeft="5sp"
android:paddingRight="5sp"
android:paddingTop="2sp"
android:paddingBottom="2sp"
android:textStyle="bold"
android:clickable="false"
/>
</TableRow>
<TableRow
android:clickable="false"
android:linksClickable="false"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:text="This is example text. It should not be clickable, but it is."
android:textSize="14sp"
android:paddingLeft="5sp"
android:paddingRight="5sp"
android:paddingTop="2sp"
android:paddingBottom="2sp"
android:scrollHorizontally="false"
android:inputType="textMultiLine"
android:linksClickable="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="0sp"
/>
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
最佳答案
我找到了解决方案,当我将 android:longClickable="false"
添加到 TextView 时,它起作用了。我总共只需要 TextView 中的这两个设置:
android:longClickable="false"
android:clickable="false"
不需要在 TableRow 中设置。
关于android - 如何使 TextView 中的文本在布局 XML 中不可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8287508/