1
Both the button and Listview do not change when clicked, but the settings when the item is not pressed work.
Listview:
<ListView
android:id="@+id/listaListas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#FFECECEC"
android:dividerHeight="2sp"
android:layout_alignParentEnd="true"
android:layout_above="@+id/novalista"
android:background="@drawable/layout_item_listview">
</ListView>
layout_item_listview:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_selected="true"
android:drawable="@drawable/layout_item_selecionado" />
<item android:state_pressed="false" android:state_selected="false"
android:drawable="@drawable/layout_item_normal" />
</selector>
layout_item_selected:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/item_selecionado"/>
</shape>
layout_item_normal:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/vermelho"/>
</shape>
Boot:
<ImageButton
android:layout_width="70dp"
android:layout_height="80dp"
android:background="@color/amarelo"
android:src="@drawable/img_estrelabotao"
android:id="@+id/btnfavorito"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:visibility="visible"
style="@style/estiloBotaoFavorito"/>
styleBotaoFavorite:
<style name="estiloBotaoFavorito">
<item name="android:background">@drawable/layout_botao_favorito</item>
<item name="android:textColor">@color/icons</item>
<item name="android:textSize">15dp</item>
</style>
layout_favorite boot:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/layout_botao_favorito_pressionado"/>
<item android:state_pressed="false" android:drawable="@drawable/layout_botao_favorito_normal"/>
</selector>
layout_botao_favorito_pressionado:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid
android:drawable="@drawable/nine_patch_retangulo"
android:color="@color/amarelo_escuro"
android:elevation="8dp"/>
</shape>
layout_botao_favorito_normal:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid
android:drawable="@drawable/nine_patch_retangulo"
android:color="@color/amarelo"
android:elevation="8dp"/>
</shape>
Another question I have is whether inside the button Shape I can set Elevation and drawable? How did I fail I left so
I did what you said and put the choiceMode as singleChoice and continued not working
– Éowyn
I edited the answer, the state was missing
state_activated
. Pay attention to the note I added.– ramaral
It worked! Buttons were not working because besides the style I had set a background. I took the background and it worked fine! Thanks :)
– Éowyn
I have the same problem, my code is the way you spoke ramaral, but only when I click on the image button it does something, now when I click on the listview item it does not apparently select it or claim the function onClick (if I take the button works normally)my choiceMode is multipleChoice.
– João Carlos
@Joãocarlos without seeing the code becomes difficult to know the reason. See if you are doing everything described in the answer. If not solved, open a new question.
– ramaral
I asked a question of a little glance at me.https://answall.com/questions/237218/ao-addir-imagebutton-selector-de-listview-workstation? noredirect=1#comment485869_237218
– João Carlos
I saw her shortly after I commented. I see nothing wrong with the problem that indicates.
– ramaral