0
我希望能夠在Android中按下手機上的菜單按鈕並獲取用於啓用/禁用聲音的菜單。我想要開/關狀態的不同圖像。Android onCreateOptionsMenu將圖標更改爲啓用/禁用
我知道如何創建菜單;不過,我很難將菜單按鈕從一個圖像更改爲另一個圖像。有沒有人知道這一點?
感謝
下面是我的代碼:
@覆蓋 公共布爾onCreateOptionsMenu(菜單菜單){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.menu, menu);
return true;
}
公共布爾onOptionsItemSelected(菜單項項){
// Handle item selection
switch (item.getItemId()) {
case R.id.EnableDisableSounds:
if(musicflag == true)
{
HighScores db = new HighScores(this);
db.open();
if(this.soundflag == true)
db.insertSystem("1", "off", "on");
else
db.insertSystem("1", "off", "off");
db.close();
mp.pause();
musicflag = false;
}
else
{
HighScores db = new HighScores(this);
db.open();
if(this.soundflag == true)
db.insertSystem("1", "on", "on");
else
db.insertSystem("1", "on", "off");
db.close();
mp.start();
musicflag = true;
}
break;
case R.id.EnableDisableMusic :
if(soundflag == true) {
HighScores db = new HighScores(this);
db.open();
if(this.musicflag == true)
db.insertSystem("1", "on", "off");
else
db.insertSystem("1", "off", "off");
db.close();
soundflag = false;
}
else if(soundflag == false) {
HighScores db = new HighScores(this);
db.open();
if(this.musicflag == true)
db.insertSystem("1", "on", "on");
else
db.insertSystem("1", "off", "on");
db.close();
soundflag = true;
}
break;
case R.id.DeleteScores:
HighScores db = new HighScores(this);
db.open();
db.DeleteDBTable();
db.close();
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
@Mr Perkins:「我很難將菜單按鈕從一個圖像更改爲另一個圖像」 - 難度是......什麼? – CommonsWare 2010-11-13 19:39:34