leItemBackgroundBorderless用于text

leItemBackgroundBorderless用于text

本文介绍了selectableItemBackgroundBorderless用于textview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TextView 用作按钮.我想添加属性 selectableItemBackgroundBorderless ,使其在按下时具有圆形波纹效果.布局如下:

I have a TextView which is use as a button. I want to add attribute selectableItemBackgroundBorderless to have circle ripple effect when pressing. The layout is as following:

android:id="@+id/create_button"
android:layout_width="wrap_content"
android:layout_height="54dp"
...
android:background="? android:attr/selectableItemBackgroundBorderless"

因此,确实在按下时会产生圆形波纹效果,但是波纹会从textview中消失,而只是从textview底部消失(因为textview的顶部是动作栏).

As a result, indeed the circle ripple effect when pressing, but the ripple goes out of the textview, but just out of the bottom of textview (because the top of the textview is action bar).

我的问题是,为什么涟漪效应会贯穿textview底部?如您所知,我将 android:layout_height 限制为54dp.为什么这个限制没有用?

My question is, why ripple effect gets across the textview bottom? As you know, I have limited android:layout_height to 54dp. Why this limitation is useless?

推荐答案

您必须使用?android:attr/selectableItemBackground 将涟漪效应保持在 View 范围内

You have to use ?android:attr/selectableItemBackground to keep the ripple effect inside the View boundaries.

?android:attr/selectableItemBackgroundBorderless 允许效果超出 View 的范围.

?android:attr/selectableItemBackgroundBorderless allows the effect to go outside of the View.

这篇关于selectableItemBackgroundBorderless用于textview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:31