Xamarin 如何捕获并保持ImageButton状态以更改为第三个图像?
当前有以下功能-按Xamarin 如何捕获并保持ImageButton状态以更改为第三个图像?,xamarin,xamarin.android,Xamarin,Xamarin.android,当前有以下功能-按Ston,图像将变为Ston 启动和停止功能代码: button.Touch += (object sender, View.TouchEventArgs e) => { if (e.Event.Action == MotionEventActions.ButtonPress) { } }; 如果上述代码中有,则ok符号可能不会显示为附加的 如何按住停止标志,然后
Ston
,图像将变为Ston
启动和停止功能代码:
button.Touch += (object sender, View.TouchEventArgs e) =>
{
if (e.Event.Action == MotionEventActions.ButtonPress)
{
}
};
如果上述代码中有,则ok符号可能不会显示为附加的
如何按住停止标志,然后再次单击它以获得“确定”标志?您可以更改按钮。触按事件可切换到其他类似以下功能:
button.Touch += (object sender, View.TouchEventArgs e) => {
if (e.Event.Action == MotionEventActions.ButtonPress)
{
button.SetImageResource(Resource.Drawable.ic_start);
}
else if (e.Event.Action == MotionEventActions.Down)
{
button.SetImageResource(Resource.Drawable.ic_stop);
button.Touch += (object stopButtonSender, View.TouchEventArgs stopButtonEventArgs) => {
// Your logic for showing OK sign
};
}
};
确保取消订阅了上一个事件,以防止内存泄漏
button.Touch -= your_function;
您可以更改按钮。将事件触摸到以下其他功能:
button.Touch += (object sender, View.TouchEventArgs e) => {
if (e.Event.Action == MotionEventActions.ButtonPress)
{
button.SetImageResource(Resource.Drawable.ic_start);
}
else if (e.Event.Action == MotionEventActions.Down)
{
button.SetImageResource(Resource.Drawable.ic_stop);
button.Touch += (object stopButtonSender, View.TouchEventArgs stopButtonEventArgs) => {
// Your logic for showing OK sign
};
}
};
确保取消订阅了上一个事件,以防止内存泄漏
button.Touch -= your_function;
如何捕获并保持ImageButton状态以更改为第三个图像
您可以使用一个变量:
int i = 1;
每次单击ImageButton
时更改其值:
bt_im.Click += (sender, e) =>
{
if (i % 3 == 0)
{
bt_im.SetBackgroundResource(Resource.Drawable.ic_stop);
i++;
//Next time your ImageButton was clicked will set a ic_start image.
}
else if(i % 3 == 1)
{
bt_im.SetBackgroundResource(Resource.Drawable.ic_OK);
i++;
}
else if (i % 3 == 2)
{
bt_im.SetBackgroundResource(Resource.Drawable.ic_start);
i++;
}
};
如何捕获并保持ImageButton状态以更改为第三个图像
您可以使用一个变量:
int i = 1;
每次单击ImageButton
时更改其值:
bt_im.Click += (sender, e) =>
{
if (i % 3 == 0)
{
bt_im.SetBackgroundResource(Resource.Drawable.ic_stop);
i++;
//Next time your ImageButton was clicked will set a ic_start image.
}
else if(i % 3 == 1)
{
bt_im.SetBackgroundResource(Resource.Drawable.ic_OK);
i++;
}
else if (i % 3 == 2)
{
bt_im.SetBackgroundResource(Resource.Drawable.ic_start);
i++;
}
};
我修改了密码。发送方和e在第二次Touch+=
声明时声明在同一范围内。基本上,将发件人更改为发件人2,将e更改为e2可以解决此问题。请确保您正在检查MotionEventActions。在逻辑中按按钮以显示OK符号。我对代码进行了更改。发送方和e在第二次Touch+=
声明时声明在同一范围内。基本上,将发送者更改为发送者2,将e更改为e2可以解决此问题。请确保您正在检查MotionEventActions。按钮按逻辑中的,以显示OK符号。@W4y,“快速单击停止按钮”是什么意思?@W4y,您想要什么效果?请再详细一点。@W4y,我已经更新了我的答案,这是你想要的效果吗?不,对不起,上面的要求是另一个。我所描述的与解决方案中第二个的行为不同。@W4y,“快速点击停止按钮”是什么意思?@W4y,你想要什么效果?请再详细一点。@W4y,我已经更新了我的答案,这是你想要的效果吗?不,对不起,上面的要求是另一个。我所描述的与解决方案中第二个else if
的行为不同。