我有一個qr代碼掃描器,然後我有一個If else語句,我想在if語句爲true時顯示Webview,但Web視圖仍然顯示並阻止相機視圖。我該怎麼做?如何在Android中顯示WebView
PreviewCallback previewCb = new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);
if (result != 0) {
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
WebView engine = (WebView) findViewById(R.id.web_engine);
engine.removeAllViews();
for (Symbol sym : syms) {
String value = new String( sym.getData());
if(value.startsWith("http://192.168.74.1")){
scanText.setText("QR Code result: " + value);
barcodeScanned = true;
engine.setVisibility(View.VISIBLE);
engine.loadUrl(value);
}
else {
scanText.setText("QR Code result 2: " + value);
barcodeScanned = true;
engine.setVisibility(View.GONE);
}
TextView tv = (TextView) findViewById(R.id.scanText);
tv.setMovementMethod(LinkMovementMethod.getInstance());
}
}
}
};
第一:請不要做循環。其次:如果您希望WebView不再在'else'語句中顯示,只需通過'engine.setVisibility(View.GONE)'將其禁用即可。 – kiruwka