android更改图像按钮背景

Wel*_*122 4 android background image button

我似乎无法更改图像按钮的背景图像.下面是我目前正在尝试使用的代码:

ImageButton imgButton = (ImageButton) findViewById(R.id.showSportsButton);
imgButton.setBackgroundResource(R.drawable.tab2_selected);
Run Code Online (Sandbox Code Playgroud)

然而,这似乎是将新图像放在旧图像的顶部,留下了2个彼此重叠的图像.

有人知道为什么吗??

Ole*_*huk 10

要解决这个问题,你应该实施

imgButton.setImageResource(R.drawable. tab2_selected);
Run Code Online (Sandbox Code Playgroud)