0

I have the following UI presented when my ListView is empty: enter image description here

Now, I want that when the user will press this "New Reminder" layout, it'll change to a "highlighted" state (with the blue focus background in ICS and the yellow color in GB)

The layout is clickable and the onClick method is called, but there is no indication for the user while he press his finger down.

I tried setting focusable to true, but it didn't do the trick.

What can I do to give any view the default "pressed" effect?

Thank you!

Community
  • 1
  • 1
Avi Shukron
  • 6,088
  • 8
  • 50
  • 84
  • if somebody wants to get full solution, check this repository: https://github.com/shamanland/AndroidLayoutSelector there is custom clickable/checkable ```LinearLayout``` like a ```ToggleButton``` – Oleksii K. Oct 17 '13 at 12:21

4 Answers4

4

With your layout, you can set background with drawable like below.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@android:drawable/star_big_on" />
    <item android:state_pressed="true" android:drawable="@android:drawable/star_big_on" />
    <item android:drawable="@android:drawable/star_big_off" />
</selector>
niki huang
  • 1,686
  • 1
  • 11
  • 5
2

Draw-able like below

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

<item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/left_radio_selected"/>
<item android:state_enabled="false" android:drawable="@drawable/left_radio_inactive"/>
<item android:state_enabled="true"  android:state_selected="true" android:drawable="@drawable/left_radio_selected"/>
<item android:drawable="@drawable/left_radio_active"/>

and set your linerlayout.setSelected(true);

Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
Patel vaishu
  • 156
  • 5
1

I don't know if I understand you correctly. If you want to create pressed state for this layout, you have to prepare state drawable xml (more info). Up there you can set what should your layout looks like while in pressed state.

Seraphis
  • 1,026
  • 2
  • 14
  • 30
  • I would think there will be a built-in way, like "pressable", but it's working nontheless so thank you! – Avi Shukron May 19 '12 at 18:48
  • Also, see [this answer](http://stackoverflow.com/a/4534092/1044642) from another question here on SO. – matsr May 19 '12 at 18:49
0

I'm not sure but your question seems a little vague. From my understanding what you want might be suggested in this post Force a ListView item to stay "pressed" after being clicked?

Community
  • 1
  • 1
bill-x
  • 569
  • 2
  • 5
  • 13