コード例 #1
0
  boolean showFragment(Fragment fragment, String ftag, FragType type, int anim) {
    FragmentManager fragmentManager = MainActivity.getInstance().getSupportFragmentManager();
    if (getFragment(ftag) != null) {
      StringBuilder sb = new StringBuilder();
      sb.append("Fragment:");
      sb.append(fragment.getClass().getName());
      sb.append(" Tag:");
      sb.append(ftag);
      sb.append(" has exist!");
      return false;
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (anim != 0) transaction.setCustomAnimations(anim, 0);

    transaction.add(R.id.main_frame, fragment, ftag);

    // 只保留当前层和其下一�?
    if (fragmentStack.size() > 1)
      transaction.hide(fragmentStack.get(fragmentStack.size() - 2).second);
    transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
    transaction.addToBackStack(ftag);
    pushFragment(fragment, ftag);
    transaction.commitAllowingStateLoss();
    return true;
  }
コード例 #2
0
 private void clearBackStack() {
   FragmentManager fragmentManager = MainActivity.getInstance().getSupportFragmentManager();
   int count = fragmentManager.getBackStackEntryCount();
   if (count > 0) {
     BackStackEntry entry = fragmentManager.getBackStackEntryAt(0);
     fragmentManager.popBackStack(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
     popAllFragment();
   }
 }
コード例 #3
0
  public boolean closeFragment() {
    try {
      FragmentManager fragmentManager = MainActivity.getInstance().getSupportFragmentManager();
      int count = fragmentManager.getBackStackEntryCount();
      if (count > 0) {
        BackStackEntry entry = fragmentManager.getBackStackEntryAt(count - 1);

        fragmentManager.popBackStack(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        popFragment(1);
        return true;
      }
    } catch (Exception e) {
    }

    return false;
  }
コード例 #4
0
 private boolean naviMainFragment(String ftag) {
   FragmentManager fragmentManager = MainActivity.getInstance().getSupportFragmentManager();
   int count = fragmentManager.getBackStackEntryCount();
   for (int i = 0; i < count; i++) {
     BackStackEntry entry = fragmentManager.getBackStackEntryAt(i);
     if (entry != null && !TextUtils.isEmpty(ftag) && entry.getName().contains(ftag)) {
       if (i < count - 1) {
         BackStackEntry topEntry = fragmentManager.getBackStackEntryAt(i + 1);
         fragmentManager.popBackStack(topEntry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
         popFragment(fragmentStack.size() - i - 1);
       }
       return true;
     }
   }
   return false;
 }