你好我正在做一個應用程序,基本上我想知道如果我可以隱藏這些選項卡片段切換如果您需要任何我的代碼請求,有噸只是爲了片段和標籤和即時消息不知道是什麼被視爲有益的感謝。如何隱藏片段切換器選項卡allways
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) {
}
}
如果您可以發佈您用於設置菜單的代碼,這將會很有幫助。它可能在封閉活動中,而不是片段本身。 – Nickel
其相當長,但我增加了託管活動 – user3381665