我使用以下代码片段来显示TextView
:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView)findViewById(R.id.test);
GradientDrawable gd = new GradientDrawable(Orientation.TOP_BOTTOM, new int[]{0xffff0000,0xffff0000});
gd.setCornerRadius(10);
GradientDrawable gd1 = new GradientDrawable(Orientation.TOP_BOTTOM, new int[]{0xff00ff00,0xff00ff00});
gd1.setCornerRadius(10);
StateListDrawable background = new StateListDrawable();
background.addState(new int[]{android.R.attr.state_pressed}, gd1);
background.addState(StateSet.WILD_CARD, gd);
tv.setBackgroundDrawable(background);
tv.setClickable(true);
在正常状态下,它的外观是可以的:
但是当它被点击时,四个角会变成白色,看这个:
我怎样才能避免这种情况?