• Android独立于Activity或者Fragment的LoadingDialog的实现


    public class LoadDialogMgr {
    
      private static final String LOAD_TIP_DIALOG_TAG = "LoadTipDialog";
      private static LoadDialogMgr sMLoadDialogMgr;
    
      private LoadDialogMgr() {
      }
    
      public static LoadDialogMgr instance() {
        if (sMLoadDialogMgr == null) {
          sMLoadDialogMgr = new LoadDialogMgr();
        }
        return sMLoadDialogMgr;
      }
    
      public void showDialog(FragmentActivity activity) {
        FragmentManager manager = activity.getSupportFragmentManager();
        LoadTipDialog loadTipDialog;
        Fragment fragment = manager.findFragmentByTag(LOAD_TIP_DIALOG_TAG);
        if (fragment instanceof LoadTipDialog) {
          loadTipDialog = (LoadTipDialog) fragment;
        } else {
          loadTipDialog = LoadTipDialog.newInstance();
        }
        if (loadTipDialog.isAdded()) {
          return;
        }
        manager.beginTransaction()
            .remove(loadTipDialog)
            .add(loadTipDialog, LOAD_TIP_DIALOG_TAG)
            .commitAllowingStateLoss();
      }
    
      public void closeDialog(FragmentActivity activity) {
        FragmentManager manager = activity.getSupportFragmentManager();
        LoadTipDialog loadTipDialog;
        Fragment fragment = manager.findFragmentByTag(LOAD_TIP_DIALOG_TAG);
        if (fragment instanceof LoadTipDialog) {
          loadTipDialog = (LoadTipDialog) fragment;
          loadTipDialog.dismissAllowingStateLoss();
        }
      }
    
      public void showDialog() {
        Activity activity = ActivityUtil.getTopActivity();
        if (activity instanceof FragmentActivity) {
          showDialog((FragmentActivity) activity);
        }
      }
    
      public void closeDialog() {
        Activity activity = ActivityUtil.getTopActivity();
        if (activity instanceof FragmentActivity) {
          closeDialog((FragmentActivity) activity);
        }
      }
    
    }

    public class LoadTipDialog extends AppCompatDialogFragment {

    private View mRootView;

    public static LoadTipDialog newInstance() {
    Bundle args = new Bundle();
    LoadTipDialog fragment = new LoadTipDialog();
    fragment.setArguments(args);
    return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState) {
    mRootView = inflater.inflate(R.layout.dialog_load_tip, container, false);
    return mRootView;
    }
    }
    
    
    //R.layout.dialog_load_tip
    <?xml version="1.0> encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:padding="15dp"
    android:background="#999999"
    android:gravity="center"
    android:orientation="vertical">
    <ProgressBar
    android:id="@+id/progress_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="10dp"
    android:text=" loading..."
    android:textColor="@color/black"
    android:textSize="16sp"/>
    </LinearLayout>
     
  • 相关阅读:
    xamarin 安卓输出中文错误 乱码解决
    xamarin自定义 application 无法调试
    Xamarin中 ios 修改Assets.xcassets 文件后 无法调试和编译
    xamarin 编译出现Xamarin.Build.Forms.Tasks.GetTaskAbi 无法加载的错误解决方法
    13、最新安卓Xamarin绑定相关填坑之旅
    12、xamarin form中实现H5 网页唤醒微信支付的方法
    11、使用xamarin实现全屏播放rtmp之类的直播视频
    8.在XamarinAndroid上进一步控制包的大小
    Xamarin.Forms 中iOS通过URL Scheme判断应用是否安装
    Xamarin.Android 使用PopupMenu遇到的问题
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/10458438.html
Copyright © 2020-2023  润新知