Код: Выделить всё
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(Const.TAG_ACTIVITY, String.format("%s BaseActivity onCreate()", this.javaClass.simpleName))
enableEdgeToEdge()
initBinding()
onActivityCreate(savedInstanceState)
observeLiveData()
}
< /code>
и этот код для включения внедрения слушателей для применения правильной накладки к представлениям < /p>
override fun onActivityCreate(savedInstanceState: Bundle?) {
InsetsManager.applyBottomNavigationViewInsets(bind.bottomNavContainer)
InsetsManager.applyTutorialInsets(bind.tutorial, bind.promotionsTutorial)
}
< /code>
Вот код insetsmanager.kt < /p>
object InsetsManager {
fun applyBottomNavigationViewInsets(bottomContainerView: ViewGroup) {
ViewCompat.setOnApplyWindowInsetsListener(bottomContainerView) { v, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(insets.left, insets.top, insets.right, insets.bottom)
WindowInsetsCompat.CONSUMED
}
}
fun applyTutorialInsets(view: MainPageTutorialView, promotionsTutorial: PromotionsPageTutorialView) {
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.insetsTop = insets.top.toFloat()
view.insetsLeft = insets.left.toFloat()
view.insetsRight = insets.right.toFloat()
view.insetsBottom = insets.bottom.toFloat()
promotionsTutorial.insetsTop = insets.top.toFloat()
promotionsTutorial.insetsBottom = insets.bottom.toFloat()
WindowInsetsCompat.CONSUMED
}
}
Все работает нормально, пока я не вызову appcompatdelegate.setdefaultnightmode (// независимо Вызов < /p>
Что я уже проверил: < /strong> < /p>
- вызывается до setContentView ()
Код: Выделить всё
enableEdgeToEdge() - setOnApplyWindowinsetSlisterslistener insoer oncreate () после setContentView ()
. enableEdgeToEdge() in onStart, onResume (didn't work)
[*]Enabled configChanges="uiMode" and called enableEdgeToEdge() inside onConfigurationChanged() and manually called recreate() (didn't work)
[*]I had a LaunchMode = "singletop" в моем Androidmanifest.xml попытался удалить его (не сработал)
Эта ошибка воспроизводится мной на эмулятор и некоторые устройства Samsung. На моем личном пикселе 9 все работает нормально, как и ожидалось. < /P>
Вот несколько примеров.
Код: Выделить всё
AppCompatDelegate.MODE_NIGHT_YESКод: Выделить всё
AppCompatDelegate.MODE_NIGHT_NO(не обращайте внимания на isappearancelightstatusbar вещь, я исправите это позже)
Подробнее здесь: https://stackoverflow.com/questions/793 ... -setdefaul
Мобильная версия