【发布时间】:2018-06-21 13:51:17
【问题描述】:
我有一个选项卡布局,每个选项卡都表示我在视图页面中的一个片段。现在我尝试在底部附加一个工具栏,但 android 导航栏不断重叠它。添加边距不是一种选择,因为它在屏幕上没有导航栏的设备上看起来很奇怪。
来自主要活动的 XML:
<?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"
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=".MainActivity">
<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.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabItem
android:id="@+id/tabItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fragment_map_title" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fragment_list_title" />
</android.support.design.widget.TabLayout>
</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.CoordinatorLayout>
来自片段的 XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ballon_info_bar" />
<android.support.v7.widget.Toolbar
android:background="#2a3b4c"
android:id="@+id/ballon_info_bar"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp">
</android.support.v7.widget.Toolbar>
</RelativeLayout>
样式 XML:
<resources>
<!-- 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>
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
我发现了其他几篇关于这个主题的帖子,但没有一个能解决我的问题。
EDIT1:图像中的边距仅用于可视化。 EDIT2:根据蓝图,ViewPager 已经在导航栏后面了
【问题讨论】:
-
我认为问题在于fitsSystemWindows,它告诉Android也在导航栏和状态栏下进行绘制
-
我尝试为 ViewPager 更改 fitSystemWindows。它只会删除我为演示目的添加的边距。
-
你能发布你的 style.xml 吗?
-
当然。添加它。根据蓝图,它的 Viewpager 已经在操作栏后面。
-
尝试将
android:windowTranslucentNavigation设置为false并将这一行添加到你的style.xml<item name="android:windowDrawsSystemBarBackgrounds">false</item>
标签: android android-layout navigationbar overlap