0

I am making a music player app. When I try to add an image in the background of the button a white background comes and no image is shown up.

Help me find my error.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <Button
        android:id="@+id/button2"
        android:layout_width="128dp"
        android:layout_height="62dp"
        android:background="@drawable/icons8-material-rounded-icons-96" />
</RelativeLayout>

see below image

Android
  • 1,420
  • 4
  • 13
  • 23

4 Answers4

2

Name of the image is not right ,when you build this project in gives error so please change image name icons_material_rounded_icons_96 and then it will show background of button.it will work for me.

Ashish
  • 116
  • 4
0

When you are copying your image to the drawable you were asked to move between two folders move to another folder which is not v24.

Steps:

  • Delete the image
  • Again Copy the image to the drawable folder and this time choose the other folder which is not v24 This will solve your issue

For more details check this answer Newer versions of Android Studio and only two drawable directory - drawable and drawable-v21

GOVIND DIXIT
  • 1,748
  • 10
  • 27
  • Tried as you told. Nothing changed still the problem is coming. – Garvit Garg Jul 23 '19 at 05:36
  • Here is the link for the image of my screen. In-text view it shows that the image has been assigned to the button but when we preview no image is coming. https://drive.google.com/open?id=1RAhTdXeX5yp7Bcv8RG8ZALxTdkOA2rxR – Garvit Garg Jul 23 '19 at 05:42
0

Try to use an Image button if you want to show an image instead of text

<ImageButton
    android:src="@drawable/icons8-material-rounded-icons-96"
    android:id="@+id/button2"
    android:layout_width="128dp"
    android:layout_height="62dp" />

Also make sure you have moved the image to drawable folder as mentioned by @GOVIND DIXIT

sanoJ
  • 2,935
  • 2
  • 8
  • 18
0

you can use ImageView

 <ImageView
                android:id="@+id/dateClosure"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginTop="3dp"
                android:layout_marginBottom="3dp"
                android:background="@color/secondary_color"  
                android:layout_weight="1.5"
                android:src="@drawable/calender2" />   

background:- this is your background on which your image will be displayed.

src:- here put your image which will be displayed above your background