androidx.fragment.app.FragmentManager.addOnBackStackChangedListener()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中androidx.fragment.app.FragmentManager.addOnBackStackChangedListener()方法的一些代码示例,展示了FragmentManager.addOnBackStackChangedListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FragmentManager.addOnBackStackChangedListener()方法的具体详情如下:
包路径:androidx.fragment.app.FragmentManager
类名称:FragmentManager
方法名:addOnBackStackChangedListener

FragmentManager.addOnBackStackChangedListener介绍

暂无

代码示例

代码示例来源:origin: pranavpandey/dynamic-support

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getSupportFragmentManager().addOnBackStackChangedListener(
      new FragmentManager.OnBackStackChangedListener() {
    @Override
    public void onBackStackChanged() {
      final int fragmentsCount =
          getSupportFragmentManager().getBackStackEntryCount();
      if (fragmentsCount > 0) {
        mContentFragmentTag = getSupportFragmentManager()
            .getBackStackEntryAt(fragmentsCount - 1).getName();
        if (mContentFragmentTag != null) {
          mContentFragment = getSupportFragmentManager()
              .findFragmentByTag(mContentFragmentTag);
        }
      } else {
        mContentFragment = getSupportFragmentManager()
            .findFragmentById(R.id.ads_container);
      }
    }
  });
  if (savedInstanceState != null) {
    mFABVisibility = ADS_VISIBILITY_FAB_NO_CHANGE;
    mContentFragmentTag = savedInstanceState.getString(ADS_STATE_CONTENT_FRAGMENT_TAG);
    mContentFragment = getSupportFragmentManager().findFragmentByTag(mContentFragmentTag);
  }
}

代码示例来源:origin: WireGuard/wireguard-android

@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main_activity);
  actionBar = getSupportActionBar();
  isTwoPaneLayout = findViewById(R.id.master_detail_wrapper) instanceof LinearLayout;
  listFragment = (TunnelListFragment) getSupportFragmentManager().findFragmentByTag("LIST");
  getSupportFragmentManager().addOnBackStackChangedListener(this);
  onBackStackChanged();
  final View actionBarView = findViewById(R.id.action_bar);
  if (actionBarView != null)
    actionBarView.setOnTouchListener((v, e) -> listFragment != null && listFragment.collapseActionMenu());
}

代码示例来源:origin: MCMrARM/revolution-irc

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_settings);
  getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  getSupportFragmentManager().addOnBackStackChangedListener(() -> {
    updateTitle();
  });
  if (getSupportFragmentManager().findFragmentById(R.id.content_frame) == null) {
    getSupportFragmentManager().beginTransaction()
        .replace(R.id.content_frame, CategoriesFragment.newInstance())
        .commit();
  }
}

代码示例来源:origin: fennifith/Alarmio

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  alarmio = (Alarmio) getApplicationContext();
  alarmio.setListener(this);
  if (savedInstanceState == null) {
    fragment = new SplashFragment();
    getSupportFragmentManager().beginTransaction()
        .add(R.id.fragment, fragment)
        .commit();
  } else {
    if (fragment == null)
      fragment = new HomeFragment();
    getSupportFragmentManager().beginTransaction()
        .replace(R.id.fragment, fragment)
        .commit();
  }
  getSupportFragmentManager().addOnBackStackChangedListener(this);
}

相关文章