Próbuję zrobić przycisk z selektorem mój przycisk może mieć następujące stany:Android: textColor wyłączonego przycisku w selektorze nie pokazuje?
- włączony/wyłączony
- wciśnięty/nie wciśnięty
Według stany wymienione powyżej. Muszę manipulować przycisk na:
- kolor Tekst
- tła
Przycisk zaczyna się mój jest wyłączony więc powinien mieć wyłączoną textColor i niepełnosprawnych przycisk tła. Ale widzę domyślny textColor (określony w stylu) i NIE ma obrazu tła!
Oto mój selektor button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:state_enabled="false"
android:textColor="#9D9FA2"
android:drawable="@drawable/button" />
<item android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/button_pressed"/>
<item android:state_pressed="true"
android:state_enabled="false"
android:textColor="#9D9FA2"
android:drawable="@drawable/button"/>
<item android:state_pressed="false"
android:state_enabled="true"
android:drawable="@drawable/button"/>
</selector>
I tu jest moja deklaracja przycisk w moim layout.xml
<Button android:id="@+id/reserve_button"
android:text="@string/reserve_button"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:paddingRight="15dp"
android:layout_gravity="left"
style="@style/buttonStyle"
android:background="@drawable/button_selector" />
I w końcu to mój styl (gdzie moja domyślna textColor jest ustawiony)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="buttonStyle">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#282780</item>
<item name="android:textSize">18sp</item>
</style>
</resources>
Proszę pomóc!
dziękuję bardzo! Dokładnie to, czego potrzebowałem! :) –
selektory, yay! – speedynomads
Nie musisz zapisywać pliku text_color.xml w/res/drawable (zamiast w/res/color), jeśli odwołujesz się do niego przez @ drawable/text_color? – Erwan