我正在开发一个应用程序,该应用程序在MainActivity中使用导航抽屉在“框架”布局上切换片段.
这些片段之一是“帮助”片段,其中我正在使用Tab布局和VIEwpager在“关于我们”,“帮助”和“ ‘联系我们’
在棒棒糖以下的设备上一切正常, *** 作栏似乎固定在选项卡布局上(用作 *** 作栏的工具栏).
但是在Lollipop设备上,它显示为就像 *** 作栏和TabLayout分开的那样.
我如何在棒棒糖设备上也能达到同样的效果?
主要活动 :
public class MainActivity extends AppCompatActivity implements NavigationVIEw.OnNavigationItemSelectedListener {NavigationVIEw navigationVIEw;ActionbarDrawerToggle toggle;DrawerLayout drawer;FragmentManager fm = getSupportFragmentManager();@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); Toolbar toolbar = (Toolbar) findVIEwByID(R.ID.toolbar); setSupportActionbar(toolbar); getSupportActionbar().setTitle("Title"); drawer = (DrawerLayout) findVIEwByID(R.ID.drawer_layout); toggle = new ActionbarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); navigationVIEw = (NavigationVIEw) findVIEwByID(R.ID.nav_vIEw); navigationVIEw.setNavigationItemSelectedListener(this);}@OverrIDepublic boolean onNavigationItemSelected(MenuItem item) { int ID = item.getItemID(); if (ID == R.ID.nav_help) { getSupportActionbar().setTitle("Help"); fm.beginTransaction().replace(R.ID.l_frame_layout, new Help(),"help").commit(); } DrawerLayout drawer = (DrawerLayout) findVIEwByID(R.ID.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true;}
Help.java
public class Help extends Fragment {VIEwPager pager;@Nullable@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater, VIEwGroup container, Bundle savedInstanceState) { VIEw rootVIEw = inflater.inflate(R.layout.layout_help, container, false); return(rootVIEw);}@OverrIDepublic voID onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final TabLayout tabLayout = (TabLayout)getActivity(). findVIEwByID(R.ID.tllayout_helpTABLAYOUTtl); tabLayout.addTab(tabLayout.newTab().setText("ABOUT")); tabLayout.addTab(tabLayout.newTab().setText("HELP")); tabLayout.addTab(tabLayout.newTab().setText("CONTACT")); tabLayout.setTabGravity(TabLayout.GraviTY_FILL); actionbar = getActivity().getActionbar(); pager = (VIEwPager)getActivity().findVIEwByID(R.ID.vplayout_helpVIEVPAGERvp); pager.setAdapter(new MyPagerAdapter(getFragmentManager())); tabLayout.setonTabSelectedListener(new TabLayout.OnTabSelectedListener() { @OverrIDe public voID onTabSelected(TabLayout.Tab tab) { pager.setCurrentItem(tab.getposition()); } @OverrIDe public voID onTabUnselected(TabLayout.Tab tab) { } @OverrIDe public voID onTabReselected(TabLayout.Tab tab) { } }); pager.setonPagechangelistener(new VIEwPager.OnPagechangelistener() { @OverrIDe public voID onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @OverrIDe public voID onPageSelected(int position) { } @OverrIDe public voID onPageScrollStateChanged(int state) { } });}class MyPagerAdapter extends FragmentStatePagerAdapter { public MyPagerAdapter(FragmentManager fm) { super(fm); } @OverrIDe public Fragment getItem(int pos) { switch(pos) { case 0: AboutUs tab1 = new AboutUs(); return tab1; case 1: HelpRecharge tab2 = new HelpRecharge(); return tab2; case 2: ContactUs tab3 = new ContactUs(); return tab3; default: return null; } } @OverrIDe public int getCount() { return 3; }}}
解决方法:
尝试通过添加以下代码来动态设置工具栏的高度:
appbarLayout.setElevation( 0 );
总结 以上是内存溢出为你收集整理的android-TabView上带有ViewPager的TabLayout-棒棒糖设备全部内容,希望文章能够帮你解决android-TabView上带有ViewPager的TabLayout-棒棒糖设备所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)