2017-05-05 10 views
1

아래 그림과 같이 반투명 상태 표시 줄을 확장하려면 내 탭이있는 툴바의 배경 인 그래디언트를 얻으려고합니다.android는 툴바를 반투명 상태 표시 줄로 확장하면서 시스템 레이아웃에 다른 레이아웃 객체를 유지합니다.

credits to Rifayet Uday for the example

나는 이것을 달성하기 위해 LAYOUT_NO_LIMITS과 TRANSLUCENT_NAVIGATION 플래그를 사용하려고했지만, 도구 모음의 다음 절반은 상태 표시 줄 아래에 간다와 스낵은 탐색 모음에서 이동합니다.

enter image description here

이 현재 레이아웃 파일입니다

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="software.endeavor.projectg.TabbedActivity"> 

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

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/appbar_padding_top" 
     android:theme="@style/AppTheme.AppBarOverlay" 
     android:background="@drawable/main_gradient"> 

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

     </android.support.v7.widget.Toolbar> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabIndicatorColor="@android:color/white"/> 

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

    <View 
     android:id="@+id/toolbar_shadow" 
     android:layout_width="match_parent" 
     android:layout_height="12dp" 
     android:layout_below="@id/toolbar" 
     android:background="@drawable/toolbar_dropshadow" /> 

    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/swipeContainer" 
     android:layout_width="368dp" 
     android:layout_height="495dp"> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="end|bottom" 
      android:layout_margin="@dimen/fab_margin" 
      app:srcCompat="@android:drawable/ic_dialog_email" /> 

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

</LinearLayout> 

가 어떻게 아직도 적절한 시스템 레이아웃 경계를 유지하면서 상태 표시 줄에 탭 도구 모음 그라데이션 연장에 대해 갈 것입니다 규칙적인 컬러 네비게이션 바 유지?

답변

1

저는 오래 전에 비슷한 문제에 직면 해있었습니다. 그것을 해결하는 쉬운 방법은 Toolbar 및 다른보기를 아래로 밀기 위해 더미 View을 사용하는 것입니다.

더미보기 : 상태 표시 줄의 높이

보기 아래 내용 밀어.

<View 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/status_bar_height"/> 

이제 레이아웃이된다 :

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="software.endeavor.projectg.TabbedActivity"> 


    <View 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/status_bar_height"/> 

    ... 

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

난 당신이 아이디어를 얻을 수 있기를 바랍니다. 또한 dimen의 status_bar_height 값을 처리하고 Android M 또는 N (확실하지 않음)에서 상태 표시 줄 높이가 변경되었음을 유의하십시오.

본 기사 참조 상태 막대 가로 : Height of status bar in Android