开发者

How to set background image for Android button but keep the gray button?

开发者 https://www.devze.com 2022-12-30 13:27 出处:网络
I need to set a background image for an android button (text button), but I want to keep the gray button.When i use the setBackgroundResource() it has the image in place of the gray bu开发者_开发知识库

I need to set a background image for an android button (text button), but I want to keep the gray button. When i use the setBackgroundResource() it has the image in place of the gray bu开发者_开发知识库tton. How can I keep the gray button?

I tried using setCompoundDrawablesWithIntrinsicBounds, but the image only takes up part of the button, even when I have no text.

Notes: I will not have text while I display the image, but the button needs to be a TextButton because there will be text without images at times, and images with text at others.


Just to answer my own question, after hours of thinking, I realized I could just create ImageButtons and TextButtons, and set the visibility (setvisibility(8)) to the buttons when I do not need them. Setting the visibility to 8 for a view makes it be taken out of the layout, and completely disappear for the time being.

0

精彩评论

暂无评论...
验证码 换一张
取 消