ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 如何在布局XML中使TextView中的文本无法点击?

2019-07-13 01:25:54  阅读:306  来源: 互联网

标签:android android-layout textview tablerow


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

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

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

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

标签:android,android-layout,textview,tablerow
来源: https://codeday.me/bug/20190713/1444594.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有