</pre><pre name="code" class="java">就是在使用到了drawable state中属性可以参考:
<span style="font-family: Arial, Helvetica, sans-serif;">其中值得注意的地方就是设置了一个boolean类型的count进行判断这个这个暂停键和播放键之间的切换,首先是默认的是暂停的所以将count设置成false,这个时候就只可以进行点击previous和next以及播放按钮,进行播放(播放了之后就会将count置成true),在count变成了true之后就会进行点击之后通过;将它又返回到暂停处,同时这个count又会被置成false,如此循环</span>
package com.eulav.ontouch;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class MainActivity extends Activity {
Boolean count ;
ImageButton image_stop;
ImageButton image_play;
ImageButton image_previous;
ImageButton image_next;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.music);
count=false;
image_stop = (ImageButton) findViewById(R.id.image_stop);
image_play = (ImageButton) findViewById(R.id.image_play);
image_previous = (ImageButton) findViewById(R.id.image_previous);
image_next = (ImageButton) findViewById(R.id.image_next);
image_stop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
image_play.setImageResource(R.drawable.stop_item);
count=false;
}
});
image_play.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(!count){
image_play.setImageResource(R.drawable.stop_item);
count= true;}
else{
image_play.setImageResource(R.drawable.pause_item);
count=false;
}
}});
image_previous.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
image_play.setImageResource(R.drawable.pause_item);
count=false;
}
});
image_next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
image_play.setImageResource(R.drawable.pause_item);
count=false;
}
});
}
}
代码下载的位置:点击打开链接