本文整理了Java中androidx.fragment.app.FragmentManager
类的一些代码示例,展示了FragmentManager
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FragmentManager
类的具体详情如下:
包路径:androidx.fragment.app.FragmentManager
类名称:FragmentManager
暂无
代码示例来源:origin: ankidroid/Anki-Android
private void loadStudyOptionsFragment() {
boolean withDeckOptions = false;
if (getIntent().getExtras() != null) {
withDeckOptions = getIntent().getExtras().getBoolean("withDeckOptions");
}
StudyOptionsFragment currentFragment = StudyOptionsFragment.newInstance(withDeckOptions);
getSupportFragmentManager().beginTransaction().replace(R.id.studyoptions_frame, currentFragment).commit();
}
代码示例来源:origin: ankidroid/Anki-Android
/**
* Global method to show dialog fragment including adding it to back stack Note: DO NOT call this from an async
* task! If you need to show a dialog from an async task, use showAsyncDialogFragment()
*
* @param newFragment the DialogFragment you want to show
*/
public void showDialogFragment(DialogFragment newFragment) {
// DialogFragment.show() will take care of adding the fragment
// in a transaction. We also want to remove any currently showing
// dialog, so make our own transaction and take care of that here.
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
// save transaction to the back stack
ft.addToBackStack("dialog");
newFragment.show(ft, "dialog");
getSupportFragmentManager().executePendingTransactions();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void recreate_nonRetainFragmentHostingActivity() {
Fragment fragment = new Fragment();
fragment.setRetainInstance(false);
ActivityScenario<LifecycleOwnerActivity> activityScenario =
ActivityScenario.launch(LifecycleOwnerActivity.class);
assertThat(activityScenario).isNotNull();
activityScenario.onActivity(
activity -> {
activity
.getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, fragment)
.commitNow();
assertThat(activity.getSupportFragmentManager().findFragmentById(android.R.id.content))
.isSameAs(fragment);
});
activityScenario.recreate();
activityScenario.onActivity(
activity ->
assertThat(activity.getSupportFragmentManager().findFragmentById(android.R.id.content))
.isNotSameAs(fragment));
}
}
代码示例来源:origin: proninyaroslav/libretorrent
public static HeavyInstanceStorage getInstance(FragmentManager fragmentManager)
{
if (fragmentManager == null)
return null;
HeavyInstanceStorage out = (HeavyInstanceStorage)fragmentManager.findFragmentByTag(TAG);
if (out == null) {
out = new HeavyInstanceStorage();
fragmentManager.beginTransaction().add(out, TAG).commitAllowingStateLoss();
}
return out;
}
}
代码示例来源:origin: googlesamples/easypermissions
@Override
public void showRequestPermissionRationale(@NonNull String rationale,
@NonNull String positiveButton,
@NonNull String negativeButton,
@StyleRes int theme,
int requestCode,
@NonNull String... perms) {
FragmentManager fm = getSupportFragmentManager();
// Check if fragment is already showing
Fragment fragment = fm.findFragmentByTag(RationaleDialogFragmentCompat.TAG);
if (fragment instanceof RationaleDialogFragmentCompat) {
Log.d(TAG, "Found existing fragment, not showing rationale.");
return;
}
RationaleDialogFragmentCompat
.newInstance(rationale, positiveButton, negativeButton, theme, requestCode, perms)
.showAllowingStateLoss(fm, RationaleDialogFragmentCompat.TAG);
}
}
代码示例来源:origin: ankidroid/Anki-Android
public StudyOptionsFragment getFragment() {
Fragment frag = getSupportFragmentManager().findFragmentById(R.id.studyoptions_fragment);
if ((frag instanceof StudyOptionsFragment)) {
return (StudyOptionsFragment) frag;
}
return null;
}
代码示例来源:origin: westnordost/StreetComplete
@Override public void onComposeNote(long questId, QuestGroup group, String questTitle)
{
LeaveNoteInsteadFragment f = new LeaveNoteInsteadFragment();
Bundle args = QuestAnswerComponent.Companion.createArguments(questId, group);
args.putString(LeaveNoteInsteadFragment.ARG_QUEST_TITLE, questTitle);
f.setArguments(args);
getSupportFragmentManager().popBackStack(BOTTOM_SHEET, FragmentManager.POP_BACK_STACK_INCLUSIVE);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(
0, R.animator.quest_answer_form_disappear,
0, R.animator.quest_answer_form_disappear);
ft.add(R.id.map_bottom_sheet_container, f, BOTTOM_SHEET);
ft.addToBackStack(BOTTOM_SHEET);
ft.commit();
}
代码示例来源:origin: jruesga/rview
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//Save the fragment's instance
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
if (fragment != null) {
getSupportFragmentManager().putFragment(outState, FRAGMENT_TAG, fragment);
}
}
代码示例来源:origin: westnordost/StreetComplete
@Override public void onBackPressed() {
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
getSupportFragmentManager().popBackStack();
} else {
super.onBackPressed();
}
}
代码示例来源:origin: WireGuard/wireguard-android
@Override public void onBackStackChanged() {
if (actionBar == null)
return;
// Do not show the home menu when the two-pane layout is at the detail view (see above).
final int backStackEntries = getSupportFragmentManager().getBackStackEntryCount();
final int minBackStackEntries = isTwoPaneLayout ? 2 : 1;
actionBar.setDisplayHomeAsUpEnabled(backStackEntries >= minBackStackEntries);
}
代码示例来源:origin: michael-rapp/AndroidMaterialPreferences
@Override
protected final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
if (fragment == null) {
fragment = Fragment.instantiate(this, PreferenceFragment.class.getName());
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment, fragment);
transaction.commit();
}
代码示例来源:origin: wdullaer/MaterialDateTimePicker
@Override
public void onResume() {
super.onResume();
DatePickerDialog dpd = (DatePickerDialog) requireFragmentManager().findFragmentByTag("Datepickerdialog");
if(dpd != null) dpd.setOnDateSetListener(this);
}
代码示例来源:origin: ankidroid/Anki-Android
private StudyOptionsFragment getCurrentFragment() {
return (StudyOptionsFragment) getSupportFragmentManager().findFragmentById(R.id.studyoptions_frame);
}
代码示例来源:origin: jruesga/rview
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//Save the fragment's instance
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
if (fragment != null) {
getSupportFragmentManager().putFragment(outState, FRAGMENT_TAG, fragment);
}
}
代码示例来源:origin: KDE/kdeconnect-android
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
FragmentManager fm = getSupportFragmentManager();
if (fm.getBackStackEntryCount() > 0) {
fm.popBackStack();
return true;
}
}
return super.onOptionsItemSelected(item);
}
代码示例来源:origin: square/picasso
void showDetails(String url) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.sample_content, DetailFragment.newInstance(url))
.addToBackStack(null)
.commit();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void recreate_retainFragmentHostingActivity() {
Fragment fragment = new Fragment();
fragment.setRetainInstance(true);
ActivityScenario<LifecycleOwnerActivity> activityScenario =
ActivityScenario.launch(LifecycleOwnerActivity.class);
assertThat(activityScenario).isNotNull();
activityScenario.onActivity(
activity -> {
activity
.getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, fragment)
.commitNow();
assertThat(activity.getSupportFragmentManager().findFragmentById(android.R.id.content))
.isSameAs(fragment);
});
activityScenario.recreate();
activityScenario.onActivity(
activity ->
assertThat(activity.getSupportFragmentManager().findFragmentById(android.R.id.content))
.isSameAs(fragment));
}
代码示例来源:origin: andstatus/andstatus
public void show(FragmentActivity fragmentActivity) {
FragmentTransaction ft = fragmentActivity.getSupportFragmentManager().beginTransaction();
Fragment prev = fragmentActivity.getSupportFragmentManager().findFragmentByTag(dialogTag);
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
show(ft, dialogTag);
}
代码示例来源:origin: wdullaer/MaterialDateTimePicker
@Override
public void onResume() {
super.onResume();
TimePickerDialog tpd = (TimePickerDialog) requireFragmentManager().findFragmentByTag("Timepickerdialog");
if(tpd != null) tpd.setOnTimeSetListener(this);
}
代码示例来源:origin: guardianproject/haven
private void switchCamera() {
String camera = mPrefManager.getCamera();
if (camera.equals(PreferenceManager.FRONT))
mPrefManager.setCamera(PreferenceManager.BACK);
else if (camera.equals(PreferenceManager.BACK))
mPrefManager.setCamera(PreferenceManager.FRONT);
((CameraFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_camera)).updateCamera();
setResult(RESULT_OK);
}
内容来源于网络,如有侵权,请联系作者删除!