Fix edge to edge

This commit is contained in:
Light_summer
2024-10-04 12:37:42 +08:00
parent b9ab00fdae
commit 6c2e7aef65
2 changed files with 30 additions and 4 deletions

View File

@@ -13,7 +13,10 @@ import android.view.Menu
import android.view.ViewGroup import android.view.ViewGroup
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ipc.RootService import com.topjohnwu.superuser.ipc.RootService
@@ -32,16 +35,36 @@ class MainActivity : AppCompatActivity() {
private val prefs by lazy { getSharedPreferences("settings", MODE_PRIVATE) } private val prefs by lazy { getSharedPreferences("settings", MODE_PRIVATE) }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
// Enable edge to edge
enableEdgeToEdge() enableEdgeToEdge()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false window.isNavigationBarContrastEnforced = false
} }
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater) binding = ActivityMainBinding.inflate(layoutInflater)
adapter = Adapter()
binding.list.adapter = adapter
setContentView(binding.root) setContentView(binding.root)
setSupportActionBar(binding.toolbar) setSupportActionBar(binding.toolbar)
// Add insets
ViewCompat.setOnApplyWindowInsetsListener(binding.appbar) { v, insets ->
val cutoutAndBars = insets.getInsets(
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
)
v.updatePadding(left = cutoutAndBars.left, top = cutoutAndBars.top, right = cutoutAndBars.right)
return@setOnApplyWindowInsetsListener insets
}
ViewCompat.setOnApplyWindowInsetsListener(binding.list) { v, insets ->
val cutoutAndBars = insets.getInsets(
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
)
v.updatePadding(left = cutoutAndBars.left, bottom = cutoutAndBars.bottom, right = cutoutAndBars.right)
return@setOnApplyWindowInsetsListener insets
}
adapter = Adapter()
binding.list.adapter = adapter
binding.swipeRefresh.setOnRefreshListener { binding.swipeRefresh.setOnRefreshListener {
refresh() refresh()
} }

View File

@@ -2,11 +2,13 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:id="@+id/appbar"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/list"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.MaterialToolbar
@@ -23,6 +25,7 @@
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" > app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" >
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/list" android:id="@+id/list"
android:clipToPadding="false"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />