This is the error I get: W/TextView: TextView does not support text selection. Selection cancelled.
I am stunned, because other Textviews
I have implemented before in a RelativeLayout
have had text selectable when I have the property android:textIsSelectable="true"
- however, doesn't work this time.
This code is placed under app_bar_main.xml
using an include
keyword in XML.
Here is 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>
Here is the edited 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>
This TextView main1
is not selectable and throws the aforementioned warning on LogCat. Please help. Thanks. (I have already tried setting focusable and setFocusable properties)
Your code works fine, I am not sure what config you have on your system.
Try the following fix
Try this in java.
textview.setTextIsSelectable(true);
textview.setFocusable(true);
textview.setFocusableInTouchMode(true);
Change TextView
width to wrap_content
from match_parent
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With