我的 EditText
和 Button
View 有这个问题,我有一个很好的填充让它们远离文本,但是当我改变背景时setBackgroundDrawable
或 setBackgroundResource
填充永远丢失。
最佳答案
我发现添加一个 9 补丁作为背景资源会重置填充 - 虽然有趣的是,如果我添加了一个颜色或非 9 补丁图像,它没有。解决方案是在添加背景之前保存填充值,然后再设置它们。
private EditText value = (EditText) findViewById(R.id.value);
int pL = value.getPaddingLeft();
int pT = value.getPaddingTop();
int pR = value.getPaddingRight();
int pB = value.getPaddingBottom();
value.setBackgroundResource(R.drawable.bkg);
value.setPadding(pL, pT, pR, pB);
关于android - 设置背景Drawable时填充在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10095196/