2015-11-24 29 views
6

Tôi đang sử dụng CoordinatorLayout với RelativeLayout để hiển thị Quảng cáo ở dưới cùng. Nhưng những gì tôi nhận được là thanh trạng thái trắng. Khi tôi loại bỏ bố cục tương đối và tất cả mọi thứ đều hoạt động tốt. Khi tôi gói CoordinatorLayout bên trong RelativeLayout, cái tôi nhận được là thanh trạng thái trắng.Thanh trạng thái màu trắng khi sử dụng AdMob trong bố cục hoạt động

Sử dụng v23 API (marshmallow)

Tôi cũng thấy câu hỏi có liên quan ở đây: Status bar turns white and does not show content behind it

Việc bố trí sử dụng tôi trông giống như câu trả lời ở đây: https://stackoverflow.com/a/31065486/1820644

Nhưng không giúp tôi. Tôi vẫn nhận được thanh trạng thái trắng.

My activity_layout.xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.testapp.EventActivity"> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/adView"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appbar" 
      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:layout_scrollFlags="scroll|enterAlways" 
       app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

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

     <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" 
      android:src="@drawable/btn_plus_add" /> 

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

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     ads:adSize="SMART_BANNER" 
     ads:adUnitId="@string/banner_ad_test_id" /> 

</RelativeLayout> 

enter image description here

Cảm ơn trước!

Trả lời

10

Sau khi thử hầu như tất cả bố cục, bố trí lồng nhau, thứ cuối cùng đã làm việc là Đặt một CoordinatorLayout làm gốc và đặt một CoordinatorLayout khác bên trong nó ở trên adView.

Các hệ thống phân cấp Layout mà tôi sử dụng là một cái gì đó như thế này:

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

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

     <android.support.design.widget.CoordinatorLayout 
      .... 
      android:layout_above="@+id/adView"> 

      <android.support.v4.view.ViewPager 
       ... /> 

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

     <com.google.android.gms.ads.AdView 
      android:id="@+id/adView" 
      ... /> 

    </RelativeLayout> 

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

Vì vậy, khi CoordinatorLayout là gốc nó làm cho chắc chắn về màu statusbar.

Những gì tôi đã cố gắng để đạt được thực hiện thông qua làm tổ của CoordinatorLayoutCoordinatorLayout như phần tử gốc của bố trí hoạt động.

Toàn mã của file layout của tôi:

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

    <RelativeLayout 
     android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.design.widget.CoordinatorLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/adView"> 

      <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:layout_scrollFlags="scroll|enterAlways" 
        app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

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

      <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" 
       android:src="@drawable/btn_plus_add" /> 

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

     <com.google.android.gms.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" 
      ads:adSize="SMART_BANNER" 
      ads:adUnitId="@string/banner_ad_bottom_event" /> 

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

cuối cùng Nó quay sang thể trông như thế này:

enter image description here

+0

nó hoạt động ngay cả với một bố trí điều phối viên độc thân và không có RelativeLayout ở tất cả. – Mikhail

Các vấn đề liên quan