简体   繁体   English

Android-我使用StateListDrawable时的丑陋盒子

[英]Android - Ugly box when I use StateListDrawable

I am using the following code - 我正在使用以下代码-

StateListDrawable states2 = new StateListDrawable();
    states2.clearColorFilter();
    states2.addState(new int[] {android.R.attr.state_pressed},
        getResources().getDrawable(R.drawable.title_search_alt));
    //states.addState(new int[] {android.R.attr.state_focused},
    //    getResources().getDrawable(R.drawable.title_search_alt));
    states2.addState(new int[] { },
        getResources().getDrawable(R.drawable.inbox));
    ib2.setImageDrawable(states2);

However, when I run it, I get an ugly box surrounding my button. 但是,当我运行它时,我的按钮周围有一个难看的盒子。 How do I get rid of it? 我如何摆脱它? I cannot use XML, so the solution has to be programmatic. 我不能使用XML,所以解决方案必须是编程的。

Edit: 编辑:

looks like http://i56.tinypic.com/be645w.png supposed to look like http://i56.tinypic.com/14mdlwl.png 看起来像http://i56.tinypic.com/be645w.png应该看起来像http://i56.tinypic.com/14mdlwl.png

您需要使用android:background =“ @ null”将按钮的背景可绘制设置为其他值或空值

您可以只使用button.setBackgroundDrawable(states2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM