Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set background image for button in Android?

I Imported one image inside the drawable-mdpi, then implemented the image from button, but an error occurs no resource found here. How do I fix this issue?

I tried this:

main.xml

  <Button
        android:id="@+id/imageButtonSelector"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable-mdpi/button_focused_orange"/>

enter image description here

like image 652
SampathKumar Avatar asked Aug 20 '12 08:08

SampathKumar


People also ask

How will you add graphics to button?

Copy your image file within the Res/drawable/ directory of your project. While in XML simply go into the graphic representation (for simplicity) of your XML file and click on your ImageButton widget that you added, go to its properties sheet and click on the [...] in the src: field. Simply navigate to your image file.

How do I make an image a button in CSS?

The default button in HTML can be changed to an image using CSS. The required button is selected using the respective CSS selector. The background property can then be set to include a background image and change the image type as required. The border of the button can also be removed to show only the image itself.

How do I make an image a button in HTML?

The image buttons in the HTML document can be created by using the type attribute of an <input> element. Image buttons also perform the same function as submit buttons, but the only difference between them is that you can keep the image of your choice as a button.

What is image button?

Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button , with the standard button background that changes color during different button states.


1 Answers

All drawables are compiled under a single resource name, i.e. drawable. Android automatically chooses from which folder to take the drawable depending on the screen size, and hence you do not need to specifically point it out. Also, hard coding Android to use resources from a particular folder kind of defeats the purpose of having multiple folders for Android to choose from. To solve this issue, simply change:

    android:background="@drawable-mdbi/button_focused_orange"/>

To

    android:background="@drawable/button_focused_orange"/>
like image 68
Raghav Sood Avatar answered Oct 08 '22 09:10

Raghav Sood