Question

I use selector for ListFragment

My xml for ListFragment

<LinearLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F1F4F2"
    android:orientation="horizontal" >

    <fragment
        android:name="usanin.max.gps_logger.Fragment_Left"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="5" />

       <FrameLayout
           android:id="@+id/frag_content"
           android:layout_width="match_parent"
           android:layout_height="fill_parent"
           android:layout_weight="2" />

</LinearLayout>

xml for items ListFragment

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/arrow"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|left"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tvDescr"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical" >
        </TextView>
    </LinearLayout>

    <ImageView
        android:id="@+id/ivImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:maxHeight="20dp"
        android:minHeight="20dp" >
    </ImageView>

</LinearLayout>

to press the button I use the selector arrow.xml

<item android:state_focused="true" android:state_pressed="true"><shape>
        <gradient android:angle="90.0" android:endColor="#BA55D3" android:startColor="#800080" android:type="linear" />

        <corners android:radius="5.0dp" />
    </shape></item>
<item android:state_focused="false" android:state_pressed="true"><shape>
        <gradient android:angle="90.0" android:color="#F1F4F2" android:endColor="#53AC71" android:startColor="#53AC71" android:type="linear" />

        <corners android:radius="5.0dp" />
    </shape></item>
<item android:state_activated="true"><shape>
        <gradient android:angle="90.0" android:endColor="#3DF5E9" android:startColor="#3DF5E9" android:type="linear" />

        <corners android:radius="5.0dp" />
    </shape></item>
<item><shape>
        <gradient android:angle="90.0" android:endColor="#8E9C8B" android:startColor="#8E9C8B" android:type="linear" />

        <corners android:radius="5.0dp" />
    </shape></item>

but I have a problem, when I pressed on the button - color background changed

I tried to set the selector when pressed "android:background" but does not work

enter image description here

Was it helpful?

Solution

You should set android:listSelector="@null" on your list. Your problem are the transparent corners where the default selector is visible.

I assume you use a ListFragment, right? So at some point (xml or code) you need to have your ListView somewhere.

If you are generating the listview programmatically try to use this in your onViewCreated() of the ListFragment:

getListView().setSeletor(android.R.color.transparent);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top