How to have a transparent ImageButton: Android

后端 未结 19 1821
庸人自扰
庸人自扰 2020-11-27 08:56


        
相关标签:
19条回答
  • 2020-11-27 09:23

    The best way is using the transparent color code

    android:background="#00000000"
    

    use the color code #00000000 for making any thing transparent

    0 讨论(0)
  • 2020-11-27 09:26

    I was already adding something to the background so , This thing worked for me:

       android:backgroundTint="@android:color/transparent"
    

    (Android Studio 3.4.1)

    EDIT: only works on android api level 21 and above. for compatibility, use this instead

       android:background="@android:color/transparent"
    
    0 讨论(0)
  • 2020-11-27 09:30

    Remove this line :

    android:background="@drawable/transparent">
    

    And in your activity class set

    ImageButton btn = (ImageButton)findViewById(R.id.previous);
    btn.setAlpha(100);
    

    You can set alpha level 0 to 255

    o means transparent and 255 means opaque.

    0 讨论(0)
  • 2020-11-27 09:36

    Programmatically it can be done by :

    image_button.setAlpha(0f) // to make it full transparent
    image_button.setAlpha(0.5f) // to make it half transparent
    image_button.setAlpha(0.6f) // to make it (40%) transparent
    image_button.setAlpha(1f) // to make it opaque
    
    0 讨论(0)
  • 2020-11-27 09:37

    Use this:

    <ImageButton
     android:id="@+id/back"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@null"
     android:padding="10dp"
     android:src="@drawable/backbtn" />
    
    0 讨论(0)
  • 2020-11-27 09:37
    <ImageButton
        android:id="@+id/previous"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/media_skip_backward">
    </ImageButton>
    

    I used a transparent png for the ImageButton, and the ImageButton worked.

    0 讨论(0)
提交回复
热议问题