The code contains an alternating "Play" and "Pause" button. It works fine, but would it be possible to customize them with a Drawable image?
I've tried using
btControl.getCompoundDrawables(R.id.imgplay)
but I did not succeed.
if (btControl.getText().equals("►")) {
this.startService(intent);
cmPasstime.setBase(SystemClock.elapsedRealtime());
cmPasstime.start();
btControl.setText("■");
} else if (btControl.getText().equals("■")) {
this.stopService(intent);
cmPasstime.stop();
btControl.setText("►");
} else if (btControl.getText().equals("►")) {
this.startService(intent);
cmPasstime.start();
btControl.setText("■");
}
Is there any way to insert two images in place of "►" and "■"?
The best way is to set tag to button as identifier and take decision on its value instead of getting drawable. Like
if (((String)btControl.getTag()).equals("playing")) {
btControl.setBackgroundResource(R.drawable.paused);
btControl.setTag("paused");
// Your Code
} else if (((String)btControl.getTag()).equals("paused")) {
btControl.setBackgroundResource(R.drawable.playing);
btControl.setTag("playing");
// Your Code
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.