在CoordinatorLayout中无法选择Android TextView?(TextView不支持文本选择.选择已取消)

Zac*_*Zac 11 android textview android-layout android-relativelayout

这是我得到的错误: W/TextView: TextView does not support text selection. Selection cancelled.

我很惊讶,因为Textviews我之前已经实现过的其他RelativeLayout文件在我拥有该属性时可以选择文本android:textIsSelectable="true"- 但是,这次不起作用.

此代码放在app_bar_main.xml使用includeXML中的关键字下.

这是app_bar_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            >
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" /> //This is where the textview is added!

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

这是编辑过的content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    tools:context="com.androidterminal.MainActivity"
    tools:showIn="@layout/app_bar_main">
    //I have some other LinearLayouts here
 <RelativeLayout
        android:id="@+id/ll5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ll2"
        android:orientation="horizontal">
    <TextView
        android:id="@+id/main1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorGrey"
        android:textIsSelectable="true"
        android:textColor="#000000" />
    </RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

此TextView main1不可选,并在LogCat上引发上述警告.请帮忙.谢谢.(我已经尝试设置focusable和setFocusable属性)

44k*_*rma 6

您的代码工作正常,我不确定您的系统上有什么配置。

尝试以下修复

  1. 在Java中尝试一下。

    textview.setTextIsSelectable(true);
    textview.setFocusable(true);
    textview.setFocusableInTouchMode(true);
    
    Run Code Online (Sandbox Code Playgroud)
  2. TextView宽度wrap_content从更改为match_parent


jee*_*aja 1

看看这个,它有效,我已经删除了您在 xml 中给出的样式

在此输入图像描述