本文整理了Java中androidx.fragment.app.FragmentManager.findFragmentByTag()
方法的一些代码示例,展示了FragmentManager.findFragmentByTag()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FragmentManager.findFragmentByTag()
方法的具体详情如下:
包路径:androidx.fragment.app.FragmentManager
类名称:FragmentManager
方法名:findFragmentByTag
暂无
代码示例来源: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: wdullaer/MaterialDateTimePicker
@Override
public void onResume() {
super.onResume();
DatePickerDialog dpd = (DatePickerDialog) requireFragmentManager().findFragmentByTag("Datepickerdialog");
if(dpd != null) dpd.setOnDateSetListener(this);
}
代码示例来源:origin: wdullaer/MaterialDateTimePicker
@Override
public void onResume() {
super.onResume();
TimePickerDialog tpd = (TimePickerDialog) requireFragmentManager().findFragmentByTag("Timepickerdialog");
if(tpd != null) tpd.setOnTimeSetListener(this);
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldShowCorrectDialog_whenMissingPermissionsAndShowRationaleFromAppCompatActivity() {
grantPermissions(ONE_PERM);
showRationale(true, ALL_PERMS);
EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS);
androidx.fragment.app.Fragment dialogFragment = spyAppCompatActivity.getSupportFragmentManager()
.findFragmentByTag(RationaleDialogFragmentCompat.TAG);
assertThat(dialogFragment).isInstanceOf(RationaleDialogFragmentCompat.class);
Dialog dialog = ((RationaleDialogFragmentCompat) dialogFragment).getDialog();
assertThatHasExpectedRationale(dialog, RATIONALE);
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldShowCorrectDialog_whenMissingPermissionsAndShowRationaleFromFragment() {
grantPermissions(ONE_PERM);
showRationale(true, ALL_PERMS);
EasyPermissions.requestPermissions(spyFragment, RATIONALE, TestFragment.REQUEST_CODE, ALL_PERMS);
androidx.fragment.app.Fragment dialogFragment = spyFragment.getChildFragmentManager()
.findFragmentByTag(RationaleDialogFragmentCompat.TAG);
assertThat(dialogFragment).isInstanceOf(RationaleDialogFragmentCompat.class);
Dialog dialog = ((RationaleDialogFragmentCompat) dialogFragment).getDialog();
assertThatHasExpectedRationale(dialog, RATIONALE);
}
代码示例来源: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: googlesamples/easypermissions
@Test
public void shouldShowCorrectDialogUsingRequest_whenMissingPermissionsAndShowRationaleFromFragment() {
grantPermissions(ONE_PERM);
showRationale(true, ALL_PERMS);
PermissionRequest request = new PermissionRequest.Builder(spyFragment, TestFragment.REQUEST_CODE, ALL_PERMS)
.setPositiveButtonText(POSITIVE)
.setNegativeButtonText(NEGATIVE)
.setRationale(RATIONALE)
.setTheme(R.style.Theme_AppCompat)
.build();
EasyPermissions.requestPermissions(request);
androidx.fragment.app.Fragment dialogFragment = spyFragment.getChildFragmentManager()
.findFragmentByTag(RationaleDialogFragmentCompat.TAG);
assertThat(dialogFragment).isInstanceOf(RationaleDialogFragmentCompat.class);
Dialog dialog = ((RationaleDialogFragmentCompat) dialogFragment).getDialog();
assertThatHasExpectedButtonsAndRationale(dialog, RATIONALE, POSITIVE, NEGATIVE);
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldShowCorrectDialogUsingRequest_whenMissingPermissionsAndShowRationaleFromAppCompatActivity() {
grantPermissions(ONE_PERM);
showRationale(true, ALL_PERMS);
PermissionRequest request = new PermissionRequest.Builder(spyAppCompatActivity, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS)
.setPositiveButtonText(android.R.string.ok)
.setNegativeButtonText(android.R.string.cancel)
.setRationale(android.R.string.unknownName)
.setTheme(R.style.Theme_AppCompat)
.build();
EasyPermissions.requestPermissions(request);
androidx.fragment.app.Fragment dialogFragment = spyAppCompatActivity.getSupportFragmentManager()
.findFragmentByTag(RationaleDialogFragmentCompat.TAG);
assertThat(dialogFragment).isInstanceOf(RationaleDialogFragmentCompat.class);
Dialog dialog = ((RationaleDialogFragmentCompat) dialogFragment).getDialog();
assertThatHasExpectedButtonsAndRationale(dialog, android.R.string.unknownName,
android.R.string.ok, android.R.string.cancel);
}
代码示例来源:origin: westnordost/StreetComplete
private AbstractBottomSheetFragment getBottomSheetFragment()
{
return (AbstractBottomSheetFragment) getSupportFragmentManager().findFragmentByTag(BOTTOM_SHEET);
}
代码示例来源:origin: westnordost/StreetComplete
@Override public void onNewIntent(Intent intent)
{
OsmOAuthDialogFragment oauthFragment = (OsmOAuthDialogFragment) getFragmentManager()
.findFragmentByTag(OsmOAuthDialogFragment.TAG);
if(oauthFragment != null)
{
oauthFragment.onNewIntent(intent);
}
}
}
代码示例来源:origin: westnordost/StreetComplete
getActivity().getSupportFragmentManager().findFragmentByTag(tag);
if(locationRequestFragment != null)
代码示例来源:origin: proninyaroslav/libretorrent
@Override
public void onNegativeClicked(@Nullable View v)
{
FragmentManager fm = getFragmentManager();
if (fm == null)
return;
if (fm.findFragmentByTag(TAG_MAGNET_INCLUDE_PRIOR_DIALOG) != null)
shareMagnetRequest(false);
}
代码示例来源:origin: proninyaroslav/libretorrent
@Override
public void onPositiveClicked(@Nullable View v)
{
FragmentManager fm = getFragmentManager();
if (fm != null && fm.findFragmentByTag(TAG_DELETE_TRACKERS_DIALOG) != null)
deleteTrackers();
}
代码示例来源:origin: morogoku/MTweaks-KernelAdiutorMOD
private Fragment getFragment() {
Fragment fragment = getSupportFragmentManager()
.findFragmentByTag(BannerResizerFragment.class.getSimpleName());
if (fragment == null) {
fragment = new BannerResizerFragment();
}
return fragment;
}
代码示例来源:origin: proninyaroslav/libretorrent
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
progress = (SpinnerProgressDialog)getSupportFragmentManager().findFragmentByTag(TAG_SPINNER_PROGRESS);
}
代码示例来源:origin: jruesga/rview
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
if (fragment instanceof KeyEventBindable) {
if (((KeyEventBindable) fragment).onKeyDown(event.getKeyCode(), event)) {
return true;
}
}
}
return super.dispatchKeyEvent(event);
}
代码示例来源: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: proninyaroslav/libretorrent
@Override
public void onDestroyView()
{
super.onDestroyView();
FragmentManager fm = getFragmentManager();
if (fm == null)
return;
Fragment fragment = fm.findFragmentByTag(TAG_FETCH_ERROR_DIALOG);
/* Prevents leak the dialog in portrait mode */
if (Utils.isLargeScreenDevice(activity) && fragment != null)
((BaseAlertDialog)fragment).dismiss();
}
代码示例来源: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: jaredrummler/ColorPicker
@Override protected void onAttachedToActivity() {
super.onAttachedToActivity();
if (showDialog) {
FragmentActivity activity = (FragmentActivity) getContext();
ColorPickerDialog fragment =
(ColorPickerDialog) activity.getSupportFragmentManager().findFragmentByTag(getFragmentTag());
if (fragment != null) {
// re-bind preference to fragment
fragment.setColorPickerDialogListener(this);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!