我在“活动”中有如下所示的文本视图:1/9(holeCounter / holeNm)。我有2个在ImageView中操纵holeCounter(添加或减少数量)的图像视图,左箭头图像表示减少,右箭头图像表示增加数字。现在,当我的HoleCounter == holeNm(9/9)时,此向右箭头图像应变成另一张图像。
注意:那些箭头图像是在活动XML文件中创建的,例如:
android:background="@drawable/ic_arrow_left"
android:background="@drawable/ic_arrow_right"
我现在所拥有的:
private void setButtons() {
mBackArrow = findViewById(R.id.previous);
mForwardArrow = findViewById(R.id.next);
mBackArrow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (holeCounter > 1) {
Intent intent = getIntent();
mHoleNm = findViewById(R.id.gameHoleNumber);
holeCounter--;
mHoleNm.setText(holeCounter + "/" + intent.getStringExtra("HOLESNM"));
}
}
});
mForwardArrow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = getIntent();
int holesNm = Integer.parseInt(intent.getStringExtra("HOLESNM"));
if (holeCounter == (holesNm - 1)) {
mForwardArrow.setImageResource(R.drawable.ic_finish);
}
if (holeCounter < holesNm) {
mHoleNm = findViewById(R.id.gameHoleNumber);
holeCounter++;
mHoleNm.setText(holeCounter + "/" + intent.getStringExtra("HOLESNM"));
}
}
});
}
现在它在该右箭头上方添加了新的drawable,但是我希望该右箭头在该新图像下方消失。同样在此之后,如果用户单击左箭头,现在单击holeCounter!= holeNm,则其他图像应返回到右箭头图像。
答案 0 :(得分:0)
您应该使用android:src
代替android:background
。替换下面的代码行
android:background="@drawable/ic_arrow_left"
android:background="@drawable/ic_arrow_right"
要
android:src="@drawable/ic_arrow_left"
android:src="@drawable/ic_arrow_right"