android.app.FragmentTransaction.replace()方法的使用及代码示例

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

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

FragmentTransaction.replace介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

FragmentTransaction tx = fragmentManager.beginTransation();
tx.replace( R.id.fragment, new MyFragment() ).addToBackStack( "tag" ).commit();

代码示例来源:origin: stackoverflow.com

private SupportMapFragment mSupportMapFragment; 
 mSupportMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.mapwhere);
 if (mSupportMapFragment == null) {
   FragmentManager fragmentManager = getFragmentManager();
   FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
   mSupportMapFragment = SupportMapFragment.newInstance();
   fragmentTransaction.replace(R.id.mapwhere, mSupportMapFragment).commit();
 }
 if (mSupportMapFragment != null)
 {
   mSupportMapFragment.getMapAsync(new OnMapReadyCallback() {
     @Override public void onMapReady(GoogleMap googleMap) {
       if (googleMap != null) {
         googleMap.getUiSettings().setAllGesturesEnabled(true);
          -> marker_latlng // MAKE THIS WHATEVER YOU WANT
           CameraPosition cameraPosition = new CameraPosition.Builder().target(marker_latlng).zoom(15.0f).build();
           CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition);
           googleMap.moveCamera(cameraUpdate);
       }
     }
   });

代码示例来源:origin: yarolegovich/SlidingRootNav

private void showFragment(Fragment fragment) {
  getFragmentManager().beginTransaction()
      .replace(R.id.container, fragment)
      .commit();
}

代码示例来源:origin: Cleveroad/SlidingTutorial-Android

public void replaceTutorialFragment() {
    getFragmentManager()
        .beginTransaction()
        .replace(R.id.container, CustomTutorialFragment.newInstance())
        .commit();
  }
}

代码示例来源:origin: stackoverflow.com

@Override
protected void onCreate(final Bundle savedInstanceState)
{
  String menuFragment = getIntent().getStringExtra("menuFragment");

  FragmentManager fragmentManager = getFragmentManager();
  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

  // If menuFragment is defined, then this activity was launched with a fragment selection
  if (menuFragment != null) {

    // Here we can decide what do to -- perhaps load other parameters from the intent extras such as IDs, etc
    if (menuFragment.equals("favoritesMenuItem")) {
      FavoritesFragment favoritesFragment = new FavoritesFragment();
      fragmentTransaction.replace(android.R.id.content, favoritesFragment);
     }
  } else {
     // Activity was not launched with a menuFragment selected -- continue as if this activity was opened from a launcher (for example)
     StandardFragment standardFragment = new StandardFragment();
     fragmentTransaction.replace(android.R.id.content, standardFragment);
  }
}

代码示例来源:origin: Rukey7/MvpApp

@Override
protected void updateViews(boolean isRefresh) {
  getFragmentManager().beginTransaction().replace(R.id.settings_view, new SettingsFragment()).commit();
}

代码示例来源:origin: baoyachi/StepView

@Override
protected void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  VerticalStepViewReverseFragment mVerticalStepViewFragment = new VerticalStepViewReverseFragment();
  getFragmentManager().beginTransaction().replace(R.id.container, mVerticalStepViewFragment).commit();
}

代码示例来源:origin: TeamNewPipe/NewPipe

private void updateFragments() {
  MissionsFragment fragment = new MissionsFragment();
  getFragmentManager().beginTransaction()
      .replace(R.id.frame, fragment, MISSIONS_FRAGMENT_TAG)
      .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
      .commit();
}

代码示例来源:origin: commonsguy/cw-omnibus

private void showLorem() {
 if (lorem == null) {
  lorem=new LoremFragment();
 }
 if (!lorem.isVisible()) {
  getFragmentManager().beginTransaction()
            .replace(R.id.content, lorem).commit();
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

private void showContent() {
  if (content == null) {
   content=new ContentFragment();
  }

  if (!content.isVisible()) {
   getFragmentManager().beginTransaction()
             .replace(R.id.content, content).commit();
  }
 }
}

代码示例来源:origin: EverythingMe/overscroll-decor

private void replaceMainFragment(Fragment fragment, int titleResId) {
    getFragmentManager().beginTransaction()
        .setCustomAnimations(R.animator.fade_in_slow, R.animator.fade_out_quick)
        .replace(R.id.fragment_placeholder, fragment)
        .commit();
    getSupportActionBar().setTitle(titleResId);
  }
}

代码示例来源:origin: wangdan/AisenWeiBo

private void loadPicture(String pic) {
  PicUrls picUrls = new PicUrls();
  picUrls.setThumbnail_pic(pic.replace("large", "bmiddle").replace("small", "bmiddle"));
  ABaseFragment pictureFragment = PictureFragment.newInstance(picUrls);
  getFragmentManager().beginTransaction().replace(R.id.layContainer, pictureFragment, "PicFragment").commit();
}

代码示例来源:origin: hitherejoe/animate

@OnClick(R.id.fab_reveal)
public void onFabClick(View view) {
  mFragment = new CircularRevealedFragment();
  getFragmentManager().beginTransaction()
      .replace(mFragmentContainer.getId(), mFragment).commit();
  revealFragmentContainer(view, mFragmentContainer);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void wordClicked() {
 if (stuff == null) {
  stuff=new StuffFragment();
 }
 getFragmentManager().beginTransaction()
           .replace(R.id.content, stuff)
           .addToBackStack(null).commit();
 drawer.post(onNavChange);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCountrySelected(Country c) {
 String url=getString(c.url);
 details.loadUrl(url);
 if (details.getId() != R.id.details) {
  getFragmentManager().beginTransaction()
                .replace(R.id.mainfrag, details,
                    TAG_DETAILS)
                .addToBackStack(null).commit();
 }
}

代码示例来源:origin: robolectric/robolectric

@Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  FragmentManager fragmentManager = this.getFragmentManager();
  TestPreferenceFragment fragment = new TestPreferenceFragment();
  fragmentManager.beginTransaction().replace(android.R.id.content, fragment, FRAGMENT_TAG).commit();
 }
}

代码示例来源:origin: iMeiji/Toutiao

private void setupFragment(String fragmentName, Bundle args) {
  Fragment fragment = Fragment.instantiate(this, fragmentName, args);
  FragmentTransaction transaction = getFragmentManager().beginTransaction();
  transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
  transaction.replace(R.id.container, fragment);
  transaction.commitAllowingStateLoss();
}

代码示例来源:origin: commonsguy/cw-omnibus

private void showLorem() {
 if (lorem == null) {
  lorem=new LoremFragment();
 }
 if (!lorem.isVisible()) {
  getFragmentManager().popBackStack();
  getFragmentManager().beginTransaction()
            .replace(R.id.content, lorem).commit();
  drawer.post(onNavChange);
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

private void showContent() {
 if (content == null) {
  content=new ContentFragment();
 }
 if (!content.isVisible()) {
  getFragmentManager().popBackStack();
  getFragmentManager().beginTransaction()
            .replace(R.id.content, content).commit();
  drawer.post(onNavChange);
 }
}

代码示例来源:origin: naman14/Timber

@Override
public void onCreate(Bundle savedInstanceState) {
  if (PreferencesUtility.getInstance(this).getTheme().equals("dark"))
    setTheme(R.style.AppThemeNormalDark);
  else if (PreferencesUtility.getInstance(this).getTheme().equals("black"))
    setTheme(R.style.AppThemeNormalBlack);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_settings);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  action = getIntent().getAction();
  if (action.equals(Constants.SETTINGS_STYLE_SELECTOR)) {
    getSupportActionBar().setTitle(R.string.now_playing);
    String what = getIntent().getExtras().getString(Constants.SETTINGS_STYLE_SELECTOR_WHAT);
    Fragment fragment = StyleSelectorFragment.newInstance(what);
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction()
        .add(R.id.fragment_container, fragment).commit();
  } else {
    getSupportActionBar().setTitle(R.string.settings);
    PreferenceFragment fragment = new SettingsFragment();
    android.app.FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
        .replace(R.id.fragment_container, fragment).commit();
  }
}

相关文章