Android Панель инструментов материалов, перекрывающаяся со строкой состояния при попытке проектирования от края до края - PullRequest
0 голосов
/ 20 июня 2020

Я пытался реализовать дизайн от края до края, чтобы в полной мере использовать возможности экрана в Android Q, но у меня возникли некоторые проблемы с ним.

Мой код выглядит следующим образом:

activity:

    <androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/Drawer_Main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.main.main.MainActivity">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/Layout_Coordinator_Main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layoutFullscreen="@{true}">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/Toolbar_Main"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorOnSurface"
            android:clipChildren="false"
            android:outlineAmbientShadowColor="@color/colorShadowColor"
            android:outlineSpotShadowColor="@color/colorShadowColor"
            android:paddingStart="8dp"
            android:paddingEnd="8dp"
            app:contentInsetStartWithNavigation="0dp">

...

BindingAdapter:

@BindingAdapter("layoutFullscreen")
fun View.bindLayoutFullscreen(previousFullscreen: Boolean, fullscreen: Boolean) {
    if (previousFullscreen != fullscreen && fullscreen) {
        systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    }
}

v29 \ colors. xml (только для Android Q)

<resources>
    <!--Set the navigation bar to transparent on Q+ and allow the system to guard against-->
    <!--low contrast scenarios.-->
    <color name="nav_bar">@android:color/transparent</color>
</resources>

цветов. xml:

<!--Set the navigation bar to transparent on Q+ and allow the system to guard against-->
<!--low contrast scenarios.-->
<color name="nav_bar">@color/colorPrimaryDark</color>

темы. xml

    <!-- Status and navigation bar colors -->
    <item name="android:statusBarColor">@color/colorPrimaryDark</item>
    <item name="android:windowLightStatusBar">@bool/theme_status_bar_light</item>
    <item name="android:navigationBarColor">@color/nav_bar</item>

Навигация работает хорошо, однако моя панель инструментов перекрывается со строкой состояния как таковой:

Status bar issue

I've already tried the following:

-  false  - android: fitsSystemWindows = "true" 

Это все равно не работает.

EDIT

I Я также пробовал ответить @Gabriele Mariotti

Я добавил код ниже в свой onCreate ():

val paddingTop = _binding.ToolbarMain.paddingTop
    ViewCompat.setOnApplyWindowInsetsListener(_binding.ToolbarMain){v, insets ->
        v.updatePadding(top = paddingTop + insets.systemWindowInsetTop)
        insets
    }

Конечный результат таков:

выпуск 2

Я все еще теряю часть своей панели инструментов материалов.

Кто-нибудь может мне помочь?

1 Ответ

1 голос
/ 20 июня 2020

Вы должны обработать WindowInsets в своем AppBarLayout (или Toolbar, если вы его не используете).

Что-то вроде:

   val appbar : AppBarLayout = findViewById(R.id.appbar)
   val appbarTopPadding = appbar.paddingTop

   ViewCompat.setOnApplyWindowInsetsListener(appbar) { v, insets ->
         v.updatePadding(top = appbarTopPadding + insets.systemWindowInsets.top)
         insets
   }

С:

enter image description here

Without:

enter image description here

You can find more информация здесь .

...