admin管理员组文章数量:1122832
I have an app consisting only of a webview. I'm trying it to update for Android 15 with edge to edge.
Below the current code from layout/webview.xml
and MainActivity.kt
.
It worked well on Android 14.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=";
xmlns:tools=";
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
actionBar?.hide()
super.onCreate(savedInstanceState)
setContentView(layout.webview)
/* code from Empty Views Activity */
//enableEdgeToEdge()
ViewCompat.setOnApplyWindowInsetsListener(findViewById(id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
I added the code for edge to edge form an empty project Empty Views Activity
generated with New... - New Project...
.
Now on Android 15, the part of the app extending under the status bar is always white, even if the device has night mode on.
The example code seems to work if the ConstraintLayout
contains a Textview
, but not if it contains a WebView
.
How can we fix this?
I have an app consisting only of a webview. I'm trying it to update for Android 15 with edge to edge.
Below the current code from layout/webview.xml
and MainActivity.kt
.
It worked well on Android 14.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
actionBar?.hide()
super.onCreate(savedInstanceState)
setContentView(layout.webview)
/* code from Empty Views Activity */
//enableEdgeToEdge()
ViewCompat.setOnApplyWindowInsetsListener(findViewById(id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
I added the code for edge to edge form an empty project Empty Views Activity
generated with New... - New Project...
.
Now on Android 15, the part of the app extending under the status bar is always white, even if the device has night mode on.
The example code seems to work if the ConstraintLayout
contains a Textview
, but not if it contains a WebView
.
How can we fix this?
Share Improve this question asked Nov 21, 2024 at 9:06 Lorenz MeyerLorenz Meyer 19.9k23 gold badges82 silver badges127 bronze badges 2 |1 Answer
Reset to default 1now you need to set android:background
for ContraintLayout
. if you want to support dark mode then reference to color stored in resources
android:background="@color/status_bar_color"
and set different status_bar_color
separately in values/colors.xml
and values-night/colors.xml
. or you can detect night mode and simply use
val color = if (dark) Color.BLACK else Color.WHITE
findViewById(id.main).setBackgroundColor(color)
I'm also advising to inspect your style set for this Activity
, as wrongly configured may lead to white icons on white status bar (or black on black) - look for proper windowLightStatusBar
, windowDrawsSystemBarBackgrounds
and statusBarColor
(which won't work when you target 35+ and won't opt-out with windowOptOutEdgeToEdgeEnforcement
)
本文标签: How to layout a webview for Android 15 edge to edgeStack Overflow
版权声明:本文标题:How to layout a webview for Android 15 edge to edge - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736312226a1935024.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
android:background=""1234af"
forConstraintLayout
? – snachmsm Commented Nov 21, 2024 at 9:19