在活动布局使用Admob的白色时

在活动布局使用Admob的白色时

本文介绍了在活动布局使用Admob的白色时,状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CoordinatorLayout与RelativeLayout的在底部显示一个广告。但我得到的白色状态栏。当我删除了相对布局和AD浏览报一切工作正常。由于我包装CoordinatorLayout内RelativeLayout的是我得到的是一个白色的状态栏。

I am using CoordinatorLayout with RelativeLayout for displaying an Ad at the bottom. But what I am getting is white status bar. When I removed the relative layout and adview everything works fine. As I am wrapping CoordinatorLayout inside RelativeLayout what I get is a white status bar.

使用API​​ V23(棉花糖)

Using API v23 (marshmallow)

我也发现了相关的问题在这里:状态栏变为白色,并没有显示内容背后

I also found related question here: Status bar turns white and does not show content behind it

我使用的布局类似于此的答案:http://stackoverflow.com/a/31065486/1820644

The layout I used looks similar to the answer here: http://stackoverflow.com/a/31065486/1820644

但并没有帮助我。我仍然得到白色的状态栏。

But didn't helped me. I am still getting the white statusbar.

我的 activity_layout.xml 文件:

<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>

在此先感谢!

推荐答案

在尝试几乎所有的布局,嵌套布局,这最后的工作是把一个CoordinatorLayout为根,把另一CoordinatorLayout里面上面AD浏览报的东西。

After trying almost all the layouts, nesting layouts, the thing which finally worked was Putting a CoordinatorLayout as the root and putting another CoordinatorLayout inside it above adView.

这是我使用的布局层次结构是这样的:

The Layout hierarchy which I used is something like this:

<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>

因此​​,作为CoordinatorLayout为根它确保了状态栏的颜色。

So as CoordinatorLayout as the root it makes sure of the statusbar color.

我是想实现的是通过嵌套CoordinatorLayout的 CoordinatorLayout作为活动布局根元素

What I was trying to achieve is done through nesting of CoordinatorLayout and CoordinatorLayout as root element of activity layout.

我的布局文件全部code:

Full code of my layout file:

<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>

这最后竟然是看起来是这样的:

It finally turned to be looks like this:

这篇关于在活动布局使用Admob的白色时,状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 01:31