Hide Tablayout Bar in android

前端 未结 1 1026
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 14:42

I have a activity with toolbar ,Tablayout , viewpager with fragments like that

I want to implement toolbar

相关标签:
1条回答
  • 2021-01-06 15:06

    here is your solution, I tried this in fragment.

    1. Write two methods like below in your Main Activity which having tablayout for hiding and showing tablayout.

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

    2.Create Interface

     public interface FragmentLifecycle {
    
            public void onPauseFragment();
            public void onResumeFragment();
    
        }
    

    3. Implement interface and call hide/show tab-layout methods

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

    I hope this is useful. Happy Coding!!

    0 讨论(0)
提交回复
热议问题