My ImageButton background png image is gray, but I want him to show it is a white button, if you use PS to fill a bit less realistic, there is no way to change the background color through the attributes of the XML?
At first, I used the online approach.
<ImageButtonAndroid:tint= "#fff"Android:layout_marginright= "20DP"Android:layout_margintop= "0DP"Android:id= "@+id/message"android:layout_centervertical= "true"Android:layout_width= "30DP"Android:layout_height= "30DP"Android:background= "@color/transparent"android:src= "@drawable/message"Android:layout_toleftof= "@id/account"/>
Use the Tint property, set to White, and then set the background to transparent.
But there's a right-hand button.
And then I started debugging myself.
<ImageButtonAndroid:tint= "#fff"android:layout_centervertical= "true"Android:id= "@+id/account"Android:layout_width= "30DP"Android:layout_height= "30DP"Android:layout_alignparentright= "true"Android:layout_marginright= "5DP"Android:background= "@drawable/account"android:src= "@drawable/account" />
I will use the background image for both background and SRC
The last button, I found the white button appears, but it is not what I want, he was magnified.
And then I used the
Android:scaletype= "Centerinside"
The function of this is to display the contents of the picture in full, by scaling it down or by the original size so that the picture length/width is equal to or less than the length/width of the view
And finally got the results I wanted.
That's it!
Finally attach the use of ScaleType
The attribute of the ImageView is Android:scaletype, which is Imageview.setscaletype (Imageview.scaletype).
Android:scaletype is a size that controls how the picture resized/moved to the ImageView.
The meaning difference of Imageview.scaletype/android:scaletype value:
Center/centerCentered on the original size of the picture, when the picture is longer/wider than the length/width of the view, the center portion of the image is displayed
Center_crop/centercropProportionally enlarges the size of the image so that the image is long (wide) equal to or greater than the length (width) of the view
Center_inside/centerinsideCenter the contents of the picture in full, by scaling it down or the original size to make the picture long/wide equal to or less than the length/width of the view
Fit_center/fitcenterEnlarges/shrinks the image to the width of the view, centered on the display
Fit_end/fitendEnlarges/shrinks the image to the width of the view, displayed in the lower part of the view
Fit_start/fitstartEnlarges/shrinks the image to the width of the view, displayed in the upper part of the view
Fit_xy/fitxyPut the picturedo not scale up/down to view size display
Matrix/matrixuse a matrix to draw
Android change ImageButton to Solid color method