android - how to apply ripple effect on textview when already background set
问题描述
I want to apply ripple effect when any item click. But I can't apply each and every item
android:background="@color/tabColor"
background already set so how to use following code
android:background="?android:attr/selectableItemBackground"
<TextView
android:id="@+id/mistake_btn_tv"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="@color/tabColor"
android:gravity="center"
android:requiresFadingEdge="none"
android:text=""
android:textColor="@color/md_white_1000"
android:textSize="@dimen/txt_20"
android:textStyle="bold"
android:typeface="monospace"/>
I expect both are working there, my background "tabColor" and also ripple effect
解决方案
您可以使用自定义drawable
文件来获得涟漪效果。在这里,我与您分享代码。只需实现该代码。希望它会正常工作。
<?xml version="1.0" encoding="UTF-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@color/colorAccent"
tools:ignore="NewApi">
<item android:id="@android:id/background">
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<corners
android:radius="5dp"/>
<stroke android:width="1dp" android:color="@color/gray_text"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
</item>
</ripple>
并将其设置为背景:-
android:background="@drawable/border_ripple_gray"
推荐阅读
- javascript - 如何在Javascript中制作一个使尺寸变大的按钮?
- java - 如何从 quickfixj 中的重复组中获取价值
- laravel - 分配 ID 以在表上创建“查看详细信息”以链接到视图
- javascript - Electron 中奇怪的 IPC 消息传递行为
- java - 合并排序返回一个包含“0”的大小为 1 的数组,而不是一个已排序的数组
- reactjs - ReactJS NextJS - 使用客户端路由持久化会话信息
- tensorflow - TensorFlow:未实现:不支持将字符串转换为浮点数
- ajax - 如何使用内置的 vue 和 ajax 表单在sails.js 中进行多选工作?
- python - 如何自动化或验证智能家居设备
- python - Python将YYYYMMDD字符串转换为YYYY-MM-DD字符串而不使用日期时间