Android 再次点击安卓按钮
我想在android上创建一个手电筒应用程序,我已经按下了一个按钮。当我们点击它时,智能手机的闪光灯就会亮起。但当我再次点击按钮时,闪光灯没有熄灭 我在github上使用了以下代码: 我已经试着去做了Android 再次点击安卓按钮,android,flash,button,Android,Flash,Button,我想在android上创建一个手电筒应用程序,我已经按下了一个按钮。当我们点击它时,智能手机的闪光灯就会亮起。但当我再次点击按钮时,闪光灯没有熄灭 我在github上使用了以下代码: 我已经试着去做了 if (the_button.isChecked()) { flash.on(); the_button.setKeepScreenOn(true); } else { flash.off();
if (the_button.isChecked()) {
flash.on();
the_button.setKeepScreenOn(true);
}
else {
flash.off();
the_button.setKeepScreenOn(false);
}
XML文件:
<ToggleButton
android:id="@+id/flashlightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onToggleClicked"
android:text="ToggleButton" />
但是那不起作用。你也可以发布xml文件吗…你需要在这个按钮上放置并点击监听器------->我宁愿使用一个标志,在监听器被触发时改变它的值(例如布尔值),而不是你试图做的事情。