Set background on TextView object and maintain ripple effect

☆樱花仙子☆ 提交于 2019-12-05 17:34:50
CodeFury

I had same problem as you and fixed it using
android:foreground="?attr/selectableItemBackground" on FrameLayout.

Here is the sample FrameLayout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/more"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:foreground="?attr/selectableItemBackground">
    <ImageView
        android:id="@+id/discover_carousel_item_image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center_vertical|center_horizontal"
        android:scaleType="fitXY" />
</FrameLayout>

RippleDrawable is the solution:

RippleDrawable newImage = new RippleDrawable(
        new ColorStateList(
                new int[][]{
                        new int[]{android.R.attr.state_pressed},
                        new int[]{}
                },
                new int[] {
                        getResources().getColor(R.color.ripple_material_light),
                        getResources().getColor(R.color.ripple_material_dark),
                }),
                new BitmapDrawable(getResources(), mapBitmap),
                null);
textView.setBackground(newImage);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!