creativecreatorormaybenot creativecreatorormaybenot - 3 months ago 11
Android Question

How do I remove the toolbar out of my android app?

The title basically says everything. I want to remove this:



from my application. I am using a tabbed activity.

What I already tried to do:

I tried to use

getActionBar.hide()
in my onCreate() method and I tried to change the style/theme of the app in my AndroidManifest.xml file.

This code in my tabbed app needs the toolbar(so I can't remove it from the layout):

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);

TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);

Answer

Use getSupportActionBar instead.

If you changed your apps style to not have the actionbar and you are setting a custom toolbar(through setSupportActionBar()), then you should be using getSupportActionBar() or your custom toolbar reference everytime you want to interact with it.

If you are using AppCompat that you have to always use getSupportActionBar() and you also have to use it if the API level is lower than 11.

Comments