我正在構建Android平板電腦的應用程序框架,並且我遇到了一些ImageButton的奇怪問題。這些按鈕(Next & Prev)用於幫助瀏覽作爲框架一部分的「內容頁面」,並使用自定義背景可繪製。Android圖像按鈕表現奇怪
問題在於,無論何時點擊Prev按鈕,Next按鈕都會突出顯示,而Prev按鈕不會。起初我以爲這是一個簡單的鏈接或@ + id /問題,但執行Prev按鈕的操作,而不是Next按鈕。
下面是一些相關的代碼:
在onCreate()方法:
nextButton = (ImageButton) findViewById(R.id.nextButton);
prevButton = (ImageButton) findViewById(R.id.prevButton);
nextButton.setOnClickListener(this);
prevButton.setOnClickListener(this);
的onClick方法:
public void onClick(View v) {
if(_cpp == null){
finish();
}else if (v == nextButton) {
if (!_cpp.nextRes.equalsIgnoreCase("")) {
// load next page
_tempRes = _cpp.nextRes;
//start transition out animations
fadePageOut();
} else {
finish();
}
} else if (v == prevButton) {
if (!_cpp.prevRes.equalsIgnoreCase("")) {
// load previous page
_tempRes = _cpp.prevRes;
//start transition out animations
fadePageOut();
}
}
}
我繪製的XML:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable= "@drawable/prev_arrowhigh" />
<item android:state_pressed="true" android:state_enabled="true"
android:drawable="@drawable/prev_arrowhigh" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/prev_arrow" />
<item android:state_enabled="true" android:drawable="@drawable/prev_arrow" />
</selector>
我一直在調試和現在尋找答案兩天,沒有運氣。有趣的是,它曾經工作得很好......但即使恢復到我的項目的先前版本似乎也沒有任何幫助。
有沒有人遇到過這個問題之前或有任何想法可能是什麼原因呢?
是 「上一頁」 和「下一頁「按鈕使用相同的drawable(與旋轉)?這可能是問題 – SERPRO
不,他們使用兩個單獨的drawable。 prev_button.xml和next_button.xml。這些在佈局XML文件中設置。 – MZGS