2017-01-05 15 views
10

Jest to błąd otrzymuję: W/TextView: TextView does not support text selection. Selection cancelled.Android TextView nie można wybrać w CoordinatorLayout? (TextView nie obsługuje zaznaczenie tekstu Wybór wyłączony.)

Jestem zaskoczony, bo inne I wprowadziły wcześniej w RelativeLayout mieli zaznaczanie tekstu, kiedy mają właściwość android:textIsSelectable="true" - jednak tym razem nie działa.

Ten kod znajduje się pod app_bar_main.xml przy użyciu słowa kluczowego include w formacie XML.

Oto 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> 

Oto edytowany 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> 

Ten TextView main1 nie jest wybierany i rzuca ww ostrzeżenie na LogCat. Proszę pomóż. Dzięki. (Próbowałem już ustawiania właściwości aktywowana i setFocusable)

+0

czy możesz dodać @ style/AppTheme.PopupOverlay, @ style/ToolbarTitle. ??? beause próbowałem Twojego kodu ..i nie mam twoich stylów, więc usunąłem to z xml i działa ... to wybiera tekst ... mogę pokazać ci zrzut ekranu .. –

+0

Masz do czynienia z tym problemem w konkretnej wersji Androida lub na telefony? Spróbuj użyć android: focusable = "true" w swoim widoku tekstowym. –

+0

Spróbuj także użyć Androida: enabled = "true" –

Odpowiedz

1

Spójrz na to, to działa, usunąłem swoje style, które zostały podane w xml

enter image description here

+0

Nie, usunięcie tych stylów nie działa dla mnie. Wciąż ten sam błąd: "W/TextView: TextView nie obsługuje zaznaczania tekstu." Anulowano zaznaczenie. " – Zac

+0

Sprawdziłem również twój kod i działa dobrze w moim telefonie. –

2

Twój kod działa poprawnie, jestem nie wiesz, jaką masz konfigurację w swoim systemie.

Spróbuj następującą poprawkę

  1. spróbować tego w Javie.

    textview.setTextIsSelectable(true); 
    textview.setFocusable(true); 
    textview.setFocusableInTouchMode(true); 
    
  2. Zmień TextView szerokość do wrap_content z match_parent.

-1

logicznie myśleć, tekst może być wybrany przez długi kliknięciem .... tak TextView musi być 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" /> 
+0

Logicznie myśląc, że widok byłby długo klikalny automatycznie, gdybyś zażądał wyboru. –

2

Korzystanie poniższy CopyTextView.java może rozwiązać swój problem:

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); 
}}    

, a następnie użyj go w pliku układu

<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" /> 
Powiązane problemy