你好,所有我正在制作一个应用程序,基本上我想知道我是否可以隐藏这些标签以进行片段切换如果你需要我的任何代码请求,那么片段和标签只有吨并且我不确定什么被视为有益的感谢。
public class HomeMediaFragment extends Fragment implements
ActionBar.TabListener, ViewPager.OnPageChangeListener{
ListView list;
private ViewPager viewPager;
private MediaFragment mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = { "The Time the School Almost (Actually) Burned Down", "The time the math exams were almost cancelled", "The Time NT almost didn't get a new School"," The time the old school almost fell down","The Time NT almost got a new pool","The Time We Almost Killed Graffiti","The Time the Exams Almost Got Destroyed","The Time we had a snow day","The Time The School Almost Fell Down", "+2" };
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_media, container, false);
viewPager = (ViewPager) v.findViewById(R.id.pager);
actionBar = getActivity().getActionBar();
mAdapter = new MediaFragment(getChildFragmentManager());
if(actionBar.getTabCount() > 0){
actionBar.removeAllTabs();
}
viewPager.setAdapter(mAdapter);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
return v;
}
@Override
public void onTabSelected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {
}
@Override
public void onDestroyView() {
// TODO Auto-generated method stub
super.onDestroyView();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
@Override
public void onPageScrolled(int i, float v, int i2) {
}
@Override
public void onPageSelected(int i) {
}
@Override
public void onPageScrollStateChanged(int i) {
}
}
答案 0 :(得分:1)
取出这些内容:
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
和这些:
@Override
public void onTabUnselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {
}
第一组行是将导航模式设置为标签页,如果您只是切换片段并将标签添加到视图中,则无需这样做。第二个是在第一部分中从.setTabListener调用的侦听器。