핸드폰 자동회전을 꺼놔도 webView가 자동으로 회전을한다..
manifestes에 activity안에
android:screenOrientation="nosensor"
android:configChanges="orientation|screenSize|keyboardHidden"
android:configChanges="orientation|screenSize|keyboardHidden"
activity에서 오버라이드
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
}
super.onConfigurationChanged(newConfig)
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
}
webView 설정
val webView=binding.webView
val webSettings = webView.settings
webSettings.javaScriptEnabled = true
webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
val jsCode = "window.addEventListener('orientationchange', function() { if (window.orientation != 0) { screen.orientation.lock('portrait'); } });"
webView.evaluateJavascript(jsCode, null)
}
}
val webSettings = webView.settings
webSettings.javaScriptEnabled = true
webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
val jsCode = "window.addEventListener('orientationchange', function() { if (window.orientation != 0) { screen.orientation.lock('portrait'); } });"
webView.evaluateJavascript(jsCode, null)
}
}
이렇게 해도 회전을 하지만... 한번 회전을 하면 계속 회전을 하진 않는다.
어떻게 하면 완전히 회전을 막을 수 있을까..?
'프로젝트-주식' 카테고리의 다른 글
liveData의 Observer 중복 요청 해결 (0) | 2024.02.15 |
---|---|
MaterialAlertDialogBuilder, AlertDialog 버튼 눌렀을 때 유지or닫기 (0) | 2024.02.03 |