简体   繁体   中英

Android Default Button Click effect Is Not Shown

I wanted to implement the android default button click effect on a Relativelayout. (The material design one)

But the problem is that it works on a view like TextView, But it's not working on a RelativeLayout(I want the relativelayout to have the android default button click effect , just like a normal button ).

I have used :

style="?borderlessButtonStyle"

and

style="?buttonStyle"

But none of them seem to work. They both work on a TextView but not on a Relativelayout. Any thoughts ? Any help is greatly appreciated.

Have you added a not null OnClickListener to your RelativeLayout ?

And make sure that the layout is clickable with (in xml):

android:clickable="true"

or, in code:

relativeLayout.setClickable(true);

将其添加到您的布局:

android:background="?android:attr/selectableItemBackground"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM