Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I scale the background of a button?

I have the following button:

<Button
android:id="@+id/buttonok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/back_no_save"
android:text="OK" />

Its appearence is:

enter image description here

How can I scale down my drawable and show a small arrow?

like image 405
Bobs Avatar asked Nov 22 '11 08:11

Bobs


People also ask

How do you scale a background image?

The background-size CSS property lets you resize the background image of an element, overriding the default behavior of tiling the image at its full size by specifying the width and/or height of the image. By doing so, you can scale the image upward or downward as desired.

How do I make the background image fit my screen size?

Using CSS, you can set the background-size property for the image to fit the screen (viewport). The background-size property has a value of cover . It instructs browsers to automatically scale the width and height of a responsive background image to be the same or bigger than the viewport.

How do you change the background of a button in HTML?

Type background-color: in the quotation marks after "style=". This element is used to change the background color of the button. Type a color name or hexadecimal code after "background-color:". You can type name of a color (i.e, blue) or a hexadecimal color.


2 Answers

You could use an ImageButton and try android:scaleType

ImageView.ScaleType

like image 129
Pathos Avatar answered Oct 08 '22 11:10

Pathos


I don't hink you can from xml. There's no xml attribute that can do scaling for buttons. You can do it programatically though, in the following way :

Bitmap originalBitmap= BitmapFactory.decodeResource(getResources(), R.drawable.icon);
Bitmap scaledBitmap=Bitmap.createScaledBitmap(originalBitmap, newWidth, newHeight, true);
txt.setBackgroundDrawable(new BitmapDrawable(bit));
like image 40
rDroid Avatar answered Oct 08 '22 12:10

rDroid