i’ve a problem with my app.
Today i’ve upgrade my android studio to the last version.
I’ve runned my app on my phone, but in the activity_main.xml the include layout (that contains a new ActionBar) doesn’t show the new actionBar, but show the image behind my smartphone.
when i use the comand.
viewBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(viewBinding.root)
The actionBar doesn’t appear.
when i use
setContentView(R.layout.activity_main)
The app show my include layout with the new actionbar, but the camera doesn’t show the image behind my snartphone.
Could you please help
Many thanks
Instead of
setContentView(viewBinding.root)
try
setContentView(viewBinding.getRoot())
2
i’ve tried with setContentView(viewBinding.getRoot()), but the result its the same. i’ve noticed that my customized topbar appers until the app launch the function, startCamera()
I’ve also noticed that the customized topbar dissapear when in the startCamera, the execution reach this code
camera=cameraProvider.bindToLifecycle(
this, cameraSelector, preview, imageCapture)
private fun startCamera() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener({
// Used to bind the lifecycle of cameras to the lifecycle owner
val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
// Preview
val preview = Preview.Builder()
.build()
.also {
it.setSurfaceProvider(viewBinding.viewFinder.surfaceProvider)
}
imageCapture = ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY)
.setFlashMode(ImageCapture.FLASH_MODE_AUTO)
.build()
// Select back camera as a default
val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
try {
// Unbind use cases before rebinding
cameraProvider.unbindAll()
// Bind use cases to camera
camera=cameraProvider.bindToLifecycle(
this, cameraSelector, preview, imageCapture)
val autoFocusPoint = SurfaceOrientedMeteringPointFactory(1f, 1f)
.createPoint(.5f, .5f)
try {
val autoFocusAction = FocusMeteringAction.Builder(
autoFocusPoint,
FocusMeteringAction.FLAG_AF
).apply {
//start auto-focusing after 1 seconds
setAutoCancelDuration(1000, TimeUnit.MILLISECONDS)
}.build()
camera.cameraControl.startFocusAndMetering(autoFocusAction)
} catch (e: CameraInfoUnavailableException) {
Log.d("ERROR", "cannot access camera", e)
}
} catch(exc: Exception) {
Log.e(TAG, "Use case binding failed", exc)
}
}, ContextCompat.getMainExecutor(this))
}