?attr/selectableitembackground Effect Shows Only On Longtap
Solution 1:
I've noticed there was a change in the behavior between Lollipop and Marshmallow:
- Lollipop - it would start the ripple on press.
- Marshmallow - the ripple starts on release.
Could that be the issue?
I would stick to the device Look & Feel but you could try this suggested solution:
https://stackoverflow.com/a/34167312/348378
Or use instead a library instead, maybe like this one:
Solution 2:
You can achieve this by setting the background of a view. First of all you have to make an item_selector.xml drawable in drawable and drawable-v21. For drawable folder-
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/item_pressed"android:state_focused="true"android:state_pressed="true"/><itemandroid:drawable="@drawable/item_pressed"android:state_focused="false"android:state_pressed="true"/><itemandroid:drawable="@drawable/item_normal"android:state_focused="true"/><itemandroid:drawable="@drawable/item_normal"android:state_focused="false"android:state_pressed="false"/></selector>
For drawable-v21 folder-
<?xml version="1.0" encoding="utf-8"?><ripplexmlns:android="http://schemas.android.com/apk/res/android"android:color="?android:attr/colorControlHighlight" ><item><selectorxmlns:android="http://schemas.android.com/apk/res/android" ><itemandroid:drawable="@drawable/item_pressed"android:state_focused="true"android:state_pressed="true"/><itemandroid:drawable="@drawable/item_pressed"android:state_focused="false"android:state_pressed="true"/><itemandroid:drawable="@drawable/item_normal"android:state_focused="true"/><itemandroid:drawable="@drawable/item_normal"android:state_focused="false"android:state_pressed="false"/></selector></item></ripple>
Now all you need to do is put android:background="@drawable/item_selector" in the view tag. For example-
<LinearLayoutandroid:id="@+id/traveller_select_layout"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/item_selector"android:orientation="vertical"android:paddingBottom="10dp"android:paddingTop="5dp"><TextViewandroid:id="@+id/textTravellers"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginStart="20dp"android:text="@string/passengers"android:textColor="@color/baggage_grey"android:textSize="12sp"/></LinearLayout>
Now make item_pressed.xml in the drawable folder-
<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><solidandroid:color="@color/filter_bg"/></shape>
And the item_normal in the drawable folder-
<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><solidandroid:color="@color/white"/></shape>
Solution 3:
Without your code, it's hard to know where goes wrong. But since I have just got this implemented, share with you what I've done, and perhaps you just follow, would help you figure out the issue.
In your view that need the click for ripple
<TextView
android:id="@+id/your_view_id"
android:layout_width="match_parent"
android:layout_height="wrap_content
android:test="Testing View"
android:background="@drawable/below_drawable">
In your /drawable-v21 folder, you have your below_drawable.xml with content
<?xml version="1.0" encoding="utf-8"?><ripplexmlns:android="http://schemas.android.com/apk/res/android"android:color="@color/your_click_background_color"><itemandroid:id="@android:id/mask"><shapeandroid:shape="rectagle" ><solidandroid:color="@android:color/your_mask_color" /></shape></item></ripple>
Since the above for Lollipop (v21) only, if you want some impact to your non-lollipop (just show the color, but no ripple). You could have the below in /drawable folder the below_drawable.xml file.
<selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_pressed="true"><shapeandroid:shape="rectangle"><solidandroid:color="@color/your_click_background_color" /></shape></item></selector>
Hope this helps.
Post a Comment for "?attr/selectableitembackground Effect Shows Only On Longtap"