2016-08-20 101 views
-2

标题基本上说了一切。我想删除此:如何从我的Android应用程序中删除工具栏?

从我的应用程序。我正在使用选项卡式活动。

我已经尝试过的事情:

我想在我的onCreate()方法使用getActionBar.hide(),我试图改变应用程序的风格/主题我的AndroidManifest.xml文件。

这段代码在我的标签应用程序需要的工具栏(所以我不能从布局删除):

 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); 
+0

从主XML删除工具栏。 – sumandas

+0

这不适用于我的选项卡式活动,因为它会在我的MainActivity中出现错误。 ViewPager不能以这种方式工作:/ @sumandas – creativecreatorormaybenot

+0

您能否请共享代码 – sumandas

回答

2

使用getSupportActionBar代替。

如果您将应用风格更改为没有操作栏,并且您正在设置自定义工具栏(通过setSupportActionBar()),那么您应该在每次要与其交互时使用getSupportActionBar()或自定义工具栏参考。

如果您正在使用程序兼容性,你必须总是使用getSupportActionBar(),你也必须使用它,如果API级别低于11