Android TextView не выбирается в CoordinatorLayout? (TextView не поддерживает выбор текста. Отбор отменен)
Это ошибка, которую я получаю: W/TextView: TextView does not support text selection. Selection cancelled.
Я ошеломлен, потому что другой Textviews
, который был реализован ранее, в RelativeLayout
имел текст, который можно выбрать, когда у меня есть свойство android:textIsSelectable="true"
- однако, на этот раз не работает.
Этот код помещается под app_bar_main.xml
с использованием ключевого слова include
в XML.
Вот 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>
Вот отредактированный 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>
Этот TextView main1
не выбирается и выдает вышеупомянутое предупреждение в LogCat. Пожалуйста помоги. Благодарю. (Я уже пробовал задавать настраиваемые и setFocusable свойства)
Ответы
Ответ 1
Ваш код работает нормально, я не уверен, какой у вас в вашей конфигурации.
Попробуйте следующее исправление
Ответ 2
Использование следующей программы CopyTextView.java может решить вашу проблему:
public class CopyTextView extends EditText {
private boolean mEnabled; // is this edittext enabled
public CopyTextView(Context context) {
super(context);
}
public CopyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CopyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
try {
if (!mEnabled) return;
super.setEnabled(false);
super.setEnabled(mEnabled);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void setEnabled(boolean enabled) {
this.mEnabled = enabled;
super.setEnabled(enabled);
}}
а затем используйте его в файле макета
<com.your_package_name.CopyTextView
android:id="@+id/main1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGrey"
android:textIsSelectable="true"
android:textColor="#000000" />
Ответ 3
Посмотрите на это, он работает, я удалил ваши стили, которые вы указали в своем xml
![введите описание изображения здесь]()
Ответ 4
логическое мышление, текст может быть выбран длинным кликом.... так что textview должен быть longclickable
<TextView
android:id="@+id/main1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGrey"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textColor="#000000" />