gpt4 book ai didi

java - 如何为一个按钮添加多个操作

转载 作者:行者123 更新时间:2023-11-29 04:41:03 25 4
gpt4 key购买 nike

我尝试在一个按钮中添加播放和暂停操作这是我的代码,我只是添加了播放 Action ,你能帮帮我吗?

 fab_play_pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

timerHasStarted = true;
countDownTimer.start();


Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.custom_progressbar_drawable);
final ProgressBar mProgress = (ProgressBar) rootView.findViewById(R.id.circularProgressbar);
mProgress.setProgress(0); // Main Progress
mProgress.setSecondaryProgress(100); // Secondary Progress
mProgress.setMax(100); // Maximum Progress
mProgress.setProgressDrawable(drawable);
mProgress.setRotation(0);

ObjectAnimator animation = ObjectAnimator.ofInt(mProgress, "progress", 0, 100);
animation.setDuration(startTime);
animation.setInterpolator(new DecelerateInterpolator());
animation.start();

}
});

最佳答案

你可以这样实现:

将其设置为默认播放

    fab_play_pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = btnAdd.getText().toString();

if(text.equalsIgnoreCase("Play")){
//your code
fab_play_pause.setText("pause")
}
else if(text.equalsIgnoreCase("pause"))
{
//your code
fab_play_pause.setText("Play")
}
}
});

对于绘图:

 fab_play_pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int resId = (Integer) view.getTag();

if(resId == R.drawable.play){
//your code
//change background for pause
}
else if(resId == R.drawable.pause)
{
//your code
//change background for play
}
}
});

关于java - 如何为一个按钮添加多个操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39178838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com