I have looked at various questions on this but, couldn't get them work.
I have a button, with a background, image on top and text at the bottom. The button is dynamic and hence NO XML is available.
Code for the dynamic button:
final Button image = new Button(this);
image.setTag(i);
image.setText(buttonsList[i].toUpperCase());
image.setGravity(Gravity.CENTER);
image.setBackgroundColor(getResources().getColor(R.color.dark_grey));
if (i == Const.MainIndex.FESTIVAL_OUTLOOK_INDEX) {
try {
XmlResourceParser parser = getResources().getXml(
R.color.text_color_green);
ColorStateList colors = ColorStateList.createFromXml(
getResources(), parser);
image.setTextColor(colors);
} catch (Exception e) {
}
//setting this value to -ve decreases the
//gap between the image and text
image.setCompoundDrawablePadding(-100);
image.setCompoundDrawablesWithIntrinsicBounds(
null,
getResources().getDrawable(
R.drawable.sidemenu_image_festout), null, null);
image.setBackgroundResource(R.drawable.button_background_green);
}
Here is how the image looks now..
I want to set padding on TOP of the image. So that the image doesn't look to close to the border of the button. How can I achieve this?
I have tried setting image.setPadding(0,10,0,0)
but no effect.