1

Hi I want to emulate snapchat. Where the camera fragment have no title bar using:

onCreate

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main)

But when I swipe to the left fragment or right fragment I want the title bar to appear.

How do I do this?

Thank you for your time.

Clarify:

When the pager switch, to another item, or the main activity switch fragment I want to show the title bar.

I'm currently using FragmentPagerAdapter to emulate snapchat. Where you start at the camera fragment and if you swipe/fling left or right, you get another fragment. The transition between fragments is carousel like, unlike calling activity with another activity where the transition between the activity is more of a popup.

Unfortunately, switching between fragment, doesn't invoke different onCreate hookmethod so I cannot hide or show the window title depending on the fragment (I can do this with activity). So I want to know how would I do this with fragment.

I'm using compat v4.

mythicalprogrammer
  • 4,647
  • 6
  • 35
  • 42
  • may be you can use actionbar instead in this answer http://stackoverflow.com/questions/8500283/how-to-hide-action-bar-before-activity-is-created-and-then-show-it-again – powerfj Jul 20 '14 at 01:58

2 Answers2

2

My suggestion is that you do something like this

See here : https://developer.android.com/training/system-ui/status.html http://blog.grio.com/2014/02/androids-hiding-of-the-system-bar-fixed.html

  • Hide the Status Bar on Android 4.0 and Lower,
  • Hide the Status Bar on Android 4.1 and Higher

    ViewPager mViewPager;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
    
        mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
    
            @Override
            public void onPageSelected(int position) {
    
                if(position == 0 ){
                    showStatusBar() ;
                }else {
                    hideStatusBar();
                }
    
            }
    
            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
    
            }
    
            @Override
            public void onPageScrollStateChanged(int arg0) {
    
            }
        });
    

    }

    private void hideStatusBar() {
        // Hide status bar
         getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    
    private void showStatusBar() {
     // Show status bar
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    
Anderson K
  • 5,445
  • 5
  • 35
  • 50
1

You can use the hide and show methods your actionbar each time you slide left or right in your FragmentPagerAdapter

sample:

        getActionBar().hide(); //will hide the actionbar
        getActionBar().show(); //will show the actionbar
Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63