繁体   English   中英

如何在布局XML中无法在TextView中创建文本?

[英]How can I make text in a TextView unclickable in the layout XML?

我有不同的表行,每个表都包含一些不可点击且不可选择的信息文本。 但是当我在模拟器中运行它时,文本始终是可点击的。

这意味着,当我点击任何文本块时,其颜色会变为深灰色。 我不希望它改变。 我希望它什么都不做。

当然,我可以将深灰色设置为文本颜色,这样用户就不会看到他点击任何内容,但这不是我想要的。

我已经尝试了不同的属性,你可以在示例中看到,但没有帮助。 此外,我实际需要设置哪些不可点击的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>

我找到了解决方案,当我向TextView添加android:longClickable="false" ,它可以工作。 我只需要TextView中的这两个设置:

android:longClickable="false"
android:clickable="false"

不需要TableRow中的设置。

你需要把这些attritbutes:

         android:clickable="false"
         android:linksClickable="false"
         android:focusable="false"
         android:focusableInTouchMode="false"

在你的textview元素中也是。 现在你只是禁用行,而不是行中的单个元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM