0

Ich möchte einen Selektor in Android Studio erstellen. Ich habe eine Datei namens "button_hover.xml" im Ordner res.layout erstellt.Erstellen eines Selektors


button_hover.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_height="wrap_content" android:layout_width="wrap_content"> 
    <item android:state_focused="true" android:drawable="@drawable/bg1.png"/> 
    <item android:state_pressed="true" android:drawable="@drawable/bg2.png" /> 
    <item android:drawable="@drawable/bg3.png" /> 
</selector> 

bg1.png, bg2.png, bg3.png in meinem ziehbar Ordner existiert, kann ich Strg + Leertaste, um sie zu nennen, aber wenn Ich starte die App, die Konsole zeigt den Fehler:

Error:(5, 58) No resource found that matches the given name (at 'drawable' with value '@drawable/bg1.png'). 
Error:(6, 58) No resource found that matches the given name (at 'drawable' with value '@drawable/bg2.png'). 
Error:(7, 29) No resource found that matches the given name (at 'drawable' with value '@drawable/bg3.png'). 

Wie kann ich das beheben?

+2

Verwendung '@ ziehbar/bg1' statt, verlieren die' .png' – eriuzo

+1

entfernen .png Erweiterung von wo das Zeichen verwendet wird –

Antwort

0

Können Sie bitte überprüfen sie unter res/ziehbar geschaffen, Es scheint, sie unter von einem dieser Ordner sind:

/drawable-ldpi For low density screens. 
/drawable-mdpi For medium density screens. 
/drawable-hdpi For high resolution screens. 
/drawable-xhdpi For extra high resolution screens. 

Wenn Sie von gerade oben auf Struktur android dann wählen Sie Projekt verwenden und Sie werden Wenn Sie nicht alle Größen verwenden, sollten sie unterziehbar sein.

0

Selektor XML

<?xml version="1.0" encoding="utf-8"?> 

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" 
     android:drawable="@drawable/select_true" /> 

    <item android:state_focused="true" 
     android:drawable="@drawable/select_false" /> 

    <item android:drawable="@drawable/select_false" /> 
</selector> 

select_true XML

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

<solid 
    android:color="#44ffffff"></solid> 

<stroke android:color="#ffffff" 
    android:width="1.2dp"/> 

</shape> 

select_false XML

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 

<solid 
    android:color="#00ffffff"></solid> 

<stroke android:color="#ffffff" 
    android:width="1.3dp"/> 

</shape> 
Verwandte Themen