1

I have an app with ActionBarSherlock with custom view, the view have some clickable linear layout, but they're not responding visually to tapping/clicking. The custom view is as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:orientation="horizontal"
    android:gravity="right" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:duplicateParentState="true"
        android:layout_gravity="right"
        android:background="@drawable/toolbar_button_background_drawable"
        android:padding="10dp"
        android:gravity="center" >

        <TextView
            android:duplicateParentState="true"
            android:id="@+id/decrease_fontsize"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_marginRight="4dp"
            android:clickable="true"            
            android:text="-A"
            android:textColor="#333"
            android:textSize="14sp" />
    </LinearLayout>
</LinearLayout>

with the following drawable: (toolbar_button_background_drawable.xml)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/hover" android:state_selected="true" />
    <item android:drawable="@drawable/hover" android:state_pressed="true" />
</selector>

hover.9.png is just a background...

but when I tap on this text, the onclick listener is triggered but visually the LinearLayout is not changed

Shehabic
  • 6,787
  • 9
  • 52
  • 93

1 Answers1

0

When you set android:duplicateParentState="true" to a view, the view gets its drawable state (focused, pressed, etc.) from its direct parent rather than from itself. So the parent Layout should be clickable.

Just add android:clickable="true" to the parent layout of the inner LinearLayout.

Libin
  • 16,967
  • 7
  • 61
  • 83
  • Doesn't work, I tried all combinations like that, removing clickable=true from child, adding it to child and parent, duplicating state for child only, child and parent, none ... but it looks like something something from the ABS is forcing the styles – Shehabic May 04 '14 at 09:36