Нажатие одновременно TextView
Есть 2 TextView, в textColor из папки drawable я вставил xml файл
text.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/color_2" android:state_checked="true" /> <item android:color="@color/color_2" android:state_pressed="true" /> <item android:color="@color/color_2" android:state_activated="true" /> <item android:color="@color/color_0" /> </selector>
То есть изначальный цвет черный, при нажатии становится допустим красный, когда отпускаешь обратно становится черный. Так вот, можно ли как-то сделать так чтобы по нажатию на один TextView, красным становились оба TextView а при отпускании опять становились чёрными.
main.xml
<LinearLayout
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:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView1"
android:textColor="@drawable/text"
android:textSize="30sp"
android:textStyle="bold"
android:clickable="true"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView2"
android:textColor="@drawable/text"
android:textSize="30sp"
android:textStyle="bold"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
Ответы (1 шт):
Автор решения: LeonSolya
→ Ссылка
Напишите функцию в которой вы находите оба text view и выставьте в них необходимый цвет далее в onCrrate у каждого объекта вызвать
textView.setOnClickListener(v - >{
Ваш метод();
}) ;