How to set transparent background for Image Button in code?

前端 未结 7 551
醉话见心
醉话见心 2020-12-25 09:03

I can set ImageButton background transparent in layout.xml using:

android:background=\"@android:color/transparent\"

How I can

7条回答
  •  醉梦人生
    2020-12-25 09:48

    DON'T USE A TRANSAPENT OR NULL LAYOUT because then the button (or the generic view) will no more highlight at click!!!

    I had the same problem and finally I found the correct attribute from Android API to solve the problem. It can apply to any view

    Use this in the button specifications

    android:background="?android:selectableItemBackground"
    

    This requires API 11

提交回复
热议问题