在 android 中隐藏 Tablayout Bar

2023-12-14

我有一个活动toolbar ,Tablayout , viewpager有碎片 像那样

enter image description here I want to implement toolbar material search on all the fragments

like that enter image description here

但问题是 TAB 栏。我想在搜索打开时隐藏选项卡栏(通话、聊天、联系人)并在搜索关闭时取消隐藏

如何隐藏标签栏?

我在用this材料搜索视图实现库

布局代码如下

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

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
        <FrameLayout
            android:id="@+id/toolbar_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"

            android:minHeight="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <com.miguelcatalan.materialsearchview.MaterialSearchView
            android:id="@+id/search_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        </FrameLayout>

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

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

    <include layout="@layout/content_dashboard" />


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

这是你的解决方案,我在片段中尝试过这个。

1. 在具有隐藏和显示选项卡布局的主活动中编写如下两个方法。

    public static void showTabLayout() {
                parentTabs.setVisibility(View.VISIBLE);
            }

    public static void hideTabLayout() {
                parentTabs.setVisibility(View.GONE);

            }

2.创建接口

 public interface FragmentLifecycle {

        public void onPauseFragment();
        public void onResumeFragment();

    }

3. 实现接口并调用隐藏/显示选项卡布局方法

CameraFragment.java

package demo.com.demo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/**
 * Created by rucha on 24/11/16.
 */
public class CameraFragment extends Fragment implements FragmentLifecycle {

    public CameraFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = null;
        rootView = inflater.inflate(R.layout.fragment_blue,
                container, false);
        setupUI(rootView);
        return rootView;
    }

    private void setupUI(View rootView) {
    }


    @Override
    public void onPauseFragment() {
        MainActivity.showTabLayout();
    }

    @Override
    public void onResumeFragment() {
        MainActivity.hideTabLayout();
    }
}

我希望这有用。快乐编码!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 android 中隐藏 Tablayout Bar 的相关文章

随机推荐

  • 修改x轴位置

    当你使用plot在 Matlab 中调用函数时 y 轴和 x 轴分别位于左侧和底部 但我希望 x 轴在图的中间穿过 比例和数字如下所示 请原谅我的业余绘画技巧 但基本上我希望 x 轴移动到顶部 例如 我希望那里有数字和那些小凸起 如红线所示
  • 如何使用计时器替换Azure辅助角色中的Thread.Sleep(...)?

    有很多人说要使用的例子Timer代替Thread Sleep in an Azure Worker Role 没有问题 我很难理解的是如何编写这个代码 目前 我有以下 伪代码 timer Elapsed sender args gt DoW
  • 记住状态 chrome 扩展

    我使用 chrome 扩展来触发两个内容脚本来注入 css 如果用户打开页面 则 contentscript on js 加载 在我的 manifest json 中定义 清单 json name tools version 1 1 des
  • AngularJS 路由器配置不起作用

    我刚刚开始学习 Angular JS 我编写了一些路由测试代码 但似乎不起作用 演示应用程序 js var demoApp angular module demoApp demoApp config function routeProvid
  • 在 Ionic 中打开适用于 Android 的应用程序

    我目前正在使用 Ionic Framework 开发适用于 iOS 和 Android 的移动应用程序 我有自己的 Map API 但缺乏导航功能 当用户单击 POI 时 我的应用程序可以打开其他地图应用程序 例如 Google 地图或 W
  • Chart.js yAxes 刻度步长不起作用(小提琴)

    我创建了一个折线图 其中 y 轴选项如下 yAxes ticks precision 1 stepSize 18 1 min 148 5 max 220 9 因此 我希望 y 轴比例如下 220 9 202 8 184 7 166 6 14
  • 使用 Android proguard 忽略外部库

    我想使用 Proguard 主要是出于混淆的原因 我在 Android 中遇到了 proguard 的问题 我使用simpleframework来解析XML 它的外部 在 proguard cfg 中 keepattributes Anno
  • jsf登录超时

    好的 简单的问题 我有一个 JSF 应用程序 包含一个登录页面 问题是 如果用户加载登录页面 离开一段时间 然后尝试登录 会话就会过期并引发 ViewExpiredException 当发生这种情况时 我可以重定向回登录 但这不是很顺利 如
  • 检查 Javascript 中的时差

    如何检查 Javascript 中两个文本框的时差 凑合 减去 JavaScriptDate对象以获得它们的差异 use a constant date e g 2000 01 01 and the desired time to init
  • WinSCP 批处理文件无法工作,但可以在 CMD 中手动工作

    我的脚本 cd C Users Administrator Downloads WinSCP 5 9 2 Portable winscp com command open ftp test email protected cd facomm
  • 如何在@BeforeSuite中使用testNG @Parameters读取资源文件

    我在用testNG with Selenium webdriver2 0 In my testNG xml I have
  • takeWhile 包括与谓词匹配的实际值 (takeWhileInclusive)

    我经常看到这样的问题 我想从列表中收集值直到值匹配 但我也需要匹配值本身 尽管takeWhile就这一点来说几乎是完美的 它实际上不允许保留最后一个 或基本上匹配的 条目 一个简单的示例 显示对象的类层次结构 直到实现特定接口的第一个类 g
  • 了解 object.size() 与 nchar()

    考虑以下向量x and y x lt a y lt deparse x From nchar nchar接受一个字符向量作为参数并返回一个向量 其元素包含 x 相应元素的大小 并从 object size 计算的是对象的大小 不包括在符号表
  • 当应用程序未运行(即完全终止)时处理推送通知

    我能够向我的 IOS 设备发送推送通知 但是当我点击该通知时 它只会打开应用程序 应用程序内不显示任何消息 我使用的代码 if application applicationState UIApplicationStateActive NS
  • 使用清单在 LoadLibrary 中搜索 Windows 路径

    如果你打电话LoadLibrary没有路径 例如 LoadLibrary whatever dll Windows 通常会遵循其标准搜索算法 与查找 EXE 所用的算法相同 我的问题是这样的 假设应用程序清单指定了系统 DLL 的特定版本
  • Durandal.js 优化器不工作(空 main-built.js)

    我正在尝试让 Durandal js 优化器在我的测试项目上工作 但它似乎不会为 main built js 生成任何内容 我在 durandal amd 文件夹中的 node js 命令提示符下使用以下命令 optimizer exe v
  • MongoDB+Azure+Android:com.mongodb.WriteConcernException 错误:“不是主”代码:“10058”

    背景 您好 我正在 Azure 上运行 MongoDB 副本集 并已从 Android 应用程序中远程连接到它 我已经从所有实例中获得了很好的读取效果 更新 因为允许它们在主节点和辅助节点上读取 但是 写入数据库仍然会出现间歇性错误 并出现
  • 双向自我参照关联

    以 Ryan Bates 的 asciicast 为例 http asciicasts com episodes 163 self referential association 他以两个 User 关联结束 friends 逆朋友 鉴于用
  • 如何在 C# 中传递多个枚举值?

    有时 在阅读其他人的 C 代码时 我会看到一种方法在单个参数中接受多个枚举值 我一直以为它很整洁 但从未仔细研究过 好吧 现在我想我可能需要它 但不知道如何 设置方法签名以接受此方法 使用方法中的值 定义枚举 来实现这种事情 In my p
  • 在 android 中隐藏 Tablayout Bar

    我有一个活动toolbar Tablayout viewpager有碎片 像那样 I want to implement toolbar material search on all the fragments like that 但问题是