【发布时间】:2016-10-04 06:06:45
【问题描述】:
当我从 tab2 切换到 tab1 或 tab3 时,我想在运行时隐藏我的操作栏,但它留下了一个空格
我的活动:(带有 TabLayout 和 3 个片段)
切换到另一个选项卡,操作栏现在隐藏但有一个空格:
我正在使用 actionBar.hide / actionBar.show ,任何线索如何正确删除这个额外的空间?如果我试图实现的目标是不可能的,那么请指导我采取任何替代方式
代码:
ActionBar actionBar;
........
........
actionBar = getSupportActionBar();
........
........
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
if (tab == tab2){
actionBar.show();
}else {
actionBar.hide();
}};
添加了 Xml 代码:
包含content_main的MainActivity
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="MainActivity"
android:animateLayoutChanges="true">
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/main_layout"
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:animateLayoutChanges="true">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e4e4e4"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fillViewport="false"
android:clickable="false" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/tabs"/>
</RelativeLayout>
【问题讨论】:
-
你能发布你的代码吗?
-
@SathishKumarJ 请检查更新后的问题
-
@DixitPanchal 请检查更新后的问题