Android 如何单击按钮并显示toast
我正在按开关,若并没有闪光灯,我的吐司就会出现。 虽然现在当我运行这个代码时,我按下按钮,即使我没有flash,它也会正常切换,没有任何关闭的flash打开。 有些设备可能没有flash,这就是我想要的原因,当他们按下按钮给他们留言时Android 如何单击按钮并显示toast,android,flash,button,toast,Android,Flash,Button,Toast,我正在按开关,若并没有闪光灯,我的吐司就会出现。 虽然现在当我运行这个代码时,我按下按钮,即使我没有flash,它也会正常切换,没有任何关闭的flash打开。 有些设备可能没有flash,这就是我想要的原因,当他们按下按钮给他们留言时 提前谢谢 试试这个修改过的代码,现在当设备没有闪光灯时,您的按钮将被禁用 hasFlash = getApplicationContext().getPackageManager() .hasSystemFeature(Packag
提前谢谢 试试这个修改过的代码,现在当设备没有闪光灯时,您的按钮将被禁用
hasFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
Switch = (ImageButton) findViewById(R.id.Switch_off);
Switch.setOnClickListener(new OnClickListener() {
public void onClick( View vw) {
if (vw.getId() == R.id.Switch_off && !hasFlash) {
Log.d("tagname","string you want to execute");
Toast.makeText(getApplicationContext(),
"Sorry,your device doesn't support flashlight",
Toast.LENGTH_LONG).show();
}
}
});
您能在这里解释问题吗?包括确定
hasFlash值的代码
您在这里面临的问题是什么?我希望没有flash的设备显示此消息
hasFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
Switch = (ImageButton) findViewById(R.id.Switch_off);
if (!hasFlash) {
Log.d("tagname","string you want to execute");
Toast.makeText(getApplicationContext(),
"Sorry,your device doesn't support flashlight",
Toast.LENGTH_LONG).show();
switch.setEnabled(false);
}
Switch.setOnClickListener(new OnClickListener() {
public void onClick( View vw) {
//Do your work here
}
});