gpt4 book ai didi

android - ImageButton 打开和关闭

转载 作者:行者123 更新时间:2023-11-29 00:21:41 27 4
gpt4 key购买 nike

我如何打开和关闭 ImageButton 上的相机灯..这是我的代码

    public void liBtn(View v)
{
int tur=0;
if (tur==0)
{
Camera.Parameters p = camera.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
int tur=1;
}
if (tur==1)
{
Camera.Parameters p = camera.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.startPreview();
int tur=0;
}
}

有什么想法吗?

最佳答案

// Create a class member variable
private boolean isOn = false;

// And use it in your method
public void liBtn(View v) {
Camera.Parameters p = camera.getParameters();

if (!isOn) {
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
} else {
p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
}

camera.setParameters(p);
camera.startPreview();

isOn = !isOn;
}

关于android - ImageButton 打开和关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22576493/

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