android隐藏主页面,在android中隐藏Tablayout Bar

我有一个带有工具栏,Tablayout,带有片段的viewpager的活动

像那样

byaTA.png

我想在所有片段上实现工具栏素材搜索

像那个4l3XG.png

但问题是TAB Bar.

我想在搜索打开时隐藏标签栏(呼叫,聊天,联系人),并在搜索关闭时取消隐藏它

如何隐藏标签栏?

我正在使用this库进行材料搜索视图实现

布局代码如下

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:layout_width="match_parent"

android:layout_height="wrap_content"

android:theme="@style/AppTheme.AppBarOverlay">

android:id="@ id/toolbar_container"

android:layout_width="match_parent"

android:layout_height="wrap_content">

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

android:id="@ id/search_view"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

android:id="@ id/tabs"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:tabMode="scrollable"

app:tabGravity="center"/>

解决方法:

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

1.在主活动中编写如下所示的两种方法,其中包含用于隐藏和显示tablayout的tablayout.

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.实现界面并调用hide / show tab-layout方法

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();

}

}

我希望这很有用.快乐编码!!来源:https://www.icode9.com/content-4-404051.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值