programing tip

상태 표시 줄이 흰색으로 바뀌고 뒤에 콘텐츠가 표시되지 않습니다.

itbloger 2020. 9. 20. 09:06
반응형

상태 표시 줄이 흰색으로 바뀌고 뒤에 콘텐츠가 표시되지 않습니다.


Marshmallow에서 AppCompat을 사용해보고 있습니다. 투명 상태 표시 줄을 원하지만 흰색으로 바뀝니다. 몇 가지 솔루션을 시도했지만 저를 위해 작동하지 않았습니다 ( 투명 상태 표시 줄이 windowTranslucentNavigation = "false"와 함께 작동하지 않음 , Lollipop : 색상이 투명으로 설정된 상태 바 뒤에 그리기 ). 다음은 관련 코드입니다.

내 styles.xml

<style name="Bacon" parent="Theme.Bacon"/>

<style name="Theme.Bacon" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/theme_primary</item>
    <item name="colorPrimaryDark">@color/theme_primary_dark</item>
    <item name="colorAccent">@color/theme_accent</item>
    <item name="windowActionBar">false</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowBackground">@color/background_material_light</item>  
</style>

<style name="Theme.Bacon.Detail" parent="Bacon"/>

v21

<style name="Bacon" parent="Theme.Bacon">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

<style name="Theme.Bacon.Detail" parent="Bacon">
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

활동

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true" />

</FrameLayout>

파편

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="192dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginBottom="32dp"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:statusBarScrim="@color/black_trans80">

        <ImageView
            android:id="@+id/photo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/photo"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/anim_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

여기에 이미지 설명 입력


이 링크에서 답을 찾았습니다. 상대 레이아웃을 루트 요소로 사용하여 상태 표시 줄 색상이 변경되지 않음

그래서 우리는 제거해야합니다

      <item name="android:statusBarColor">@android:color/transparent</item>

styles.xml (v21)에서. 그리고 그것은 나를 위해 잘 작동합니다.


(파티에 조금 늦었지만 누군가에게 도움이 될 수 있습니다)

나는 똑같은 문제가 있었다. 어쨌든 일부 활동은 정상 이었지만 새로 만든 활동은 colorPrimaryDark대신 흰색 상태 표시 줄을 표시했습니다 .

몇 가지 팁을 시도한 후 모든 CoordinatorLayout것이 레이아웃의 루트로 사용되는 정상적인 작업 활동을 발견 했으며 다른 사람들은 .NET에서 제공하는 기능 (애니메이션 등)이 필요하지 않았기 때문에 일반 레이아웃으로 대체했습니다 CoordinatorLayout.

따라서 해결책은 CoordinatorLayout루트 레이아웃 을 만든 다음 그 안에 이전 레이아웃 루트를 추가하는 것입니다. 다음은 예입니다.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <!-- your activity content here-->


  </LinearLayout>
</android.support.design.widget.CoordinatorLayout>

android:fitsSystemWindows="true"이 솔루션 없이는 작동하지 않습니다.

Lollipop 및 Marshmallow에서 테스트 됨


 <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@color/colorPrimaryDark</item>
    </style

이것을 바꾸기 만하면 statusBarColor는 투명하지 않고 예상되는 색상이어야합니다.


위의 모든 것을 성공적으로 시도하지 못한 후 테마를 명시 적으로 설정하면 문제가 해결된다는 것을 알았습니다.

setTheme(R.style.AppTheme);

그것은 당신의 활동에서 super.OnCreate () 전에 가야합니다.


이것을 style.xml에 추가하십시오.

    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>

그리고 이것은 당신의 onCreate ();

 getWindow().getDecorView().setSystemUiVisibility(
       View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

이 항목을 v21 \ styles.xml에 넣으십시오.

진실

다음과 같아야합니다.

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>


콘텐츠를 보려면 스타일에이 속성을 추가해야합니다.

<item name="android:windowLightStatusBar" tools:ignore="NewApi">true</item>

<item name="android:statusBarColor">@android:color/transparent</item>

values ​​/ styles / styles.xml (v21)에서 해당 코드 줄을 볼 수 있습니다. 그것을 제거하면 문제가 해결됩니다.

이 답변에 연결


나는 같은 문제에 직면했다. 내가 한 것은 "v21 / styles.xml"파일에서 true 값을 변경 한 것입니다.

 <item name="windowDrawsSystemBarBackgrounds">true</item>

에:

 <item name="windowDrawsSystemBarBackgrounds">false</item>

내 활동 레이아웃을 FrameLayout에서 RelativeLayout으로 변경하여 문제를 해결했습니다. 도와 주신 모든 분들께 감사드립니다!

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@android:color/transparent">

    <android.support.v4.view.ViewPager
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/theme_primary_dark"
      android:fitsSystemWindows="true" />

</RelativeLayout>

hierarchy-viewer 또는 ViewInspector를 사용해보십시오 . 이러한 도구가 도움이 될 수 있습니다.


스타일 v21 @android : color / transparent에서 다음 태그를 제거하십시오.

이것은 나를 위해 작동합니다.


더 나은 접근

NoActionBar 테마가있는 style.xml 파일을 확인하십시오. 부모가 Theme.AppCompat.NoActionBar인지 확인하고 색 구성표를 추가하여 사용자 지정합니다. 마지막으로 필요에 따라 매니페스트에서 테마를 설정합니다.

아래는 내 styles.xml 파일 (ActionBar + NoActionBar)의 샘플입니다.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<!-- No ActionBar application theme. -->
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

나를 위해 다음을 수행하여 작동했습니다.

  1. 테마 설정 .NoActionBar
  2. 툴바 감싸기 android.support.design.widget.AppBarLayout
  3. android.support.design.widget.CoordinatorLayout부모 레이아웃으로 만듭니다 .

기본적으로 상태 표시 줄을 그리는 세 번째 단계입니다. colorPrimaryDark그렇지 않으면 NoActionBar테마 를 사용하는 경우 그려지지 않습니다 . 두 번째 단계는 툴바에 오버레이를 제공합니다 .


스타일 v23 용

 <style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowLightStatusBar">true</item>
    <item name="android:statusBarColor">@android:color/white</item>
</style>

스타일 v21 용

<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:statusBarColor">@android:color/white</item>
</style>

v21 / styles.xml에

<resources>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>

Then, Remove or comment below line or change colour of status bar,

<item name="android:statusBarColor">@android:color/transparent</item>

Its working fine. Hope this is helpful. Thanks.


I'm not sure if it's late but i hope it helps someone. * Make a fake view with transparent background that fits the layout, and make a coordinatorlayout as your root layout element.

<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:fitsSystemWindows="true" />


<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:scaleType="centerCrop"
    android:src="@drawable/something" />

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

   .... YOUR LAYOUT


[산출]

Expand res -> values -> styles directory from project panel.

Open styles.xml (v21)

USE ANY ONE FROM BELOW WAYS

  1. Change true to false in android:windowDrawsSystemBarBackgrounds property.
  2. Change @android:color/transparent to @color/colorPrimaryDark in android:statusBarColor property.
  3. Remove the android:statusBarColor propert line.

My guess is that this is caused by your android:windowBackground. Is @color/background_material_light a reference to white?


Check this Toolbar turns white - AppBar isn't drawn after being scrolled off screen

https://code.google.com/p/android/issues/detail?id=178037#c19

I'm using libraries 23.0.0. and the bug still occurs.

Workaround for this is adding View that takes nearly no space and can be invisible. See the structure below.

<android.support.v4.widget.NestedScrollView
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.Toolbar
        app:layout_scrollFlags="scroll|enterAlways" />

    <android.support.design.widget.TabLayout
        app:layout_scrollFlags="scroll|enterAlways" />

    <View
        android:layout_width="match_parent"
        android:layout_height=".3dp"
        android:visibility="visible"/>

</android.support.design.widget.AppBarLayout>

This Questions on Stackoverflow.com refer to this bug too: CoordinatorLayout Toolbar invisible on enter until full height AppBarLayout - Layout sometimes invisible once it enters view (even if it's not entered)


check the color schemes implemented in styles-21


If you are using RelativeLayout / CoordinatorLayout this is the solution that worked for me:

You have to use

  • CoordinatorLayout
  • AppBarLayout

RelativeLayout 대신 CoordinatorLayout을 사용하도록 Rember (성능이 더 좋고 AppBarLayout과 완벽하게 작동 함)

이것이 조각이 시작되는 방법입니다.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:fitsSystemWindows="true"
>

<android.support.design.widget.AppBarLayout
    android:id="@+id/main.appbar"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true"
    >
    ...

좋은 코딩!

참고 URL : https://stackoverflow.com/questions/32428700/status-bar-turns-white-and-does-not-show-content-behind-it

반응형