dialogx は、オープン ソースの Android ポップアップ ウィンドウ コンポーネントを推奨しています。

DialogX の利点

ダイアログは、ソフトウェアがユーザーの操作に応答してフィードバックを提供するための重要なコンポーネントであり、DialogX は開発者がこれらのタスクを迅速に完了するのに役立ちます。

開発者の心配を減らし、いつでも、どんな状況でも、簡単に使えるダイアログ部品を作ることを目指しています。

DialogX は、使いやすさを前提として、開発者が拡張できるように、よりパーソナライズされたインターフェイスを提供します。これには、ダイアログ ボックスへのカスタム レイアウトの挿入、ライト モードとダーク モードの切り替え、アプリ UI に合わせたカスタム テーマのカスタマイズさえ含まれます。

オープン ソース アドレス: https://github.com/kongzue/DialogX

✅DialogXの特徴:

  1. DialogX は新しい実装方法を採用しています. デフォルトの View 実装方法は軽量であり, Window および DialogFragment の実装方法もオプションで自由で柔軟です.
  2. DialogX の起動はスレッドとは関係なく、任意のスレッドで DialogX を起動でき、UI スレッドで自動的に実行されます。
  3. The startup of DialogX does not need the context parameter. デフォルトでは、1 行のコードでダイアログ ボックスを開始するための静的メソッドが提供されているため、より便利に使用できます。
    より自由に、開発者はダイアログ ボックス内の任意のコンポーネントのスタイルを簡単にカスタマイズできます。これには、テキスト スタイル、ボタン テキスト スタイル、メニュー テキスト スタイル、入力テキスト スタイル、タイトルと同じ大きさ、プロンプト メッセージと同じくらい小さいものなど、必要に応じて変更できます。 .
  4. DialogX はテーマ別のデザインを採用し、デフォルトで Material テーマが付属しており、オプションで IOS、Kongzue、MIUI などの他のスタイル テーマを導入できるため、アプリのサイズが大幅に縮小されます。カスタマイズが必要な場合は、一連のプライベート テーマを自分で実装できます。
  5. カップリングが低く、問題が少ないため、DialogX は、AlertDialog などのコンポーネントが原因であった WindowLeaked エラーを心配することなく、ダイアログ ボックスの実行中に自由にアクティビティを閉じることができます。
  6. For a Smoother experience, the animation Effects of DialogX are more rich. ダイアログ ボックスの起動アニメーションはノンリニア アニメーションによって実現され、プロンプトの待機からエラー アニメーションの完了までの一貫した遷移効果もあり、APP をより動的にします。
  7. すべてのテーマは、デフォルトで明るい色と暗い色の 2 つのモードをサポートします. ワンクリックで構成して明るい色と暗い色のダイアログ テーマを切り替えるだけで済みます.カスタマイズされたニーズを満たすために、より多くの自由なレイアウト コンテンツが必要です.DialogX は、システムへの自動適応もサポートしています.システム設定により、明るい色と暗い色の表示効果の切り替えが自動的に判断されます。
  8. ダイアログ ボックスのライフサイクル コントロールと没入型の適応を簡単に実現します。

導入

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }      //增加 jitPack Maven 仓库
    }
}

1.gradleを追加する

//https://github.com/kongzue/DialogX
def dialogx_version = "0.0.45"
implementation "com.github.kongzue.DialogX:DialogX:${dialogx_version}"
implementation "com.github.kongzue.DialogX:DialogXIOSStyle:${dialogx_version}"
implementation "com.github.kongzue.DialogX:DialogXKongzueStyle:${dialogx_version}"
implementation "com.github.kongzue.DialogX:DialogXMIUIStyle:${dialogx_version}"

2.アプリケーションに追加

DialogX.init(this)
DialogX.globalStyle = IOSStyle.style()

一般的な使用例をいくつか挙げます


メッセージ プロンプト ボックス ([OK] をクリック)

DialogX.globalStyle = IOSStyle.style();
MessageDialog.show("标题", "这里是正文内容。", "确定")
        .setOkButton(new OnDialogButtonClickListener<MessageDialog>() {
    
    
            @Override
            public boolean onClick(MessageDialog baseDialog, View v) {
    
    
                PopTip.show("点击确定按钮");
                return false;
            }
        });

ここに画像の説明を挿入

選択ダイアログ

DialogX.globalStyle = IOSStyle.style();
MessageDialog messageDialog = new MessageDialog("多选对话框", "移除App会将它从主屏幕移除并保留其所有数据。", "删除App", "取消", "移至App资源库")
        .setButtonOrientation(LinearLayout.VERTICAL);
if (!rdoMiui.isChecked()) {
    
    
    messageDialog.setOkTextInfo(new TextInfo().setFontColor(Color.parseColor("#EB5545")).setBold(true));
}
messageDialog.show();

ここに画像の説明を挿入

入力ボックス(テキスト入力)

DialogX.globalStyle = MaterialStyle.style();
btnInputDialog.setOnClickListener(new View.OnClickListener() {
    
    
    @Override
    public void onClick(View view) {
    
    
        new InputDialog("标题", "正文内容", "确定", "取消", "正在输入的文字")
            .setInputText("Hello World")
            .setOkButton(new OnInputDialogButtonClickListener<InputDialog>() {
    
    
                @Override
                public boolean onClick(InputDialog baseDialog, View v, String inputStr) {
    
    
                    PopTip.show("输入的内容:" + inputStr);
                    return false;
                }
            })
            .show();
    }
});

ここに画像の説明を挿入

ポップアップウィンドウ (成功/失敗)

//正确
TipDialog.show(msg, WaitDialog.TYPE.SUCCESS)

//错误
TipDialog.show(msg, WaitDialog.TYPE.ERROR)

ここに画像の説明を挿入

ここに画像の説明を挿入

メッセージプロンプト (トースト)

DialogX.globalStyle = MaterialStyle.style();
PopTip.show("这是一个提示");
PopTip.show(R.mipmap.img, "一个提示").setAutoTintIconInLightOrDarkMode(false).showLong();

ここに画像の説明を挿入

メニュー(もう一つお選びください)

//view是指显示在哪个view上面
DialogX.globalStyle = MaterialStyle.style();
PopMenu.show(view, new String[]{
    
    "选项1", "选项2", "选项3"})
    .setOnMenuItemClickListener(new OnMenuItemClickListener<PopMenu>() {
    
    
        @Override
        public boolean onClick(PopMenu dialog, CharSequence text, int index) {
    
    
            btnSelectMenu.setText(text);
            return false;
    	}
});


//设置菜单并且给菜单设置图标
DialogX.globalStyle = MaterialStyle.style();
PopMenu.show(new String[]{
    
    "添加", "编辑", "删除", "分享"})
    .setOnMenuItemClickListener(new OnMenuItemClickListener<PopMenu>() {
    
    
        @Override
        public boolean onClick(PopMenu dialog, CharSequence text, int index) {
    
    
            if (index==0){
    
    
                dialog.setMenuList(new String[]{
    
    "A","B","C"});
                return true;
            }
            return false;
        }
    })
    .setOnIconChangeCallBack(new OnIconChangeCallBack<PopMenu>(true) {
    
    
        @Override
        public int getIcon(PopMenu dialog, int index, String menuText) {
    
    
            switch (menuText) {
    
    
                case "添加":
                    return R.mipmap.img_dialogx_demo_add;
                case "编辑":
                    return R.mipmap.img_dialogx_demo_edit;
                case "删除":
                    return R.mipmap.img_dialogx_demo_delete;
                case "分享":
                    return R.mipmap.img_dialogx_demo_share;
                default:
                    return 0;
            }
        }
    });

ここに画像の説明を挿入
ここに画像の説明を挿入

下のカスタム スライド レイアウト

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll_root"
    android:layout_width="match_parent"
    android:layout_height="500dp"
    android:orientation="vertical">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="5dp"
        android:text="我是余静"
        android:textColor="@color/black"
        android:textSize="16sp" />
    <com.kongzue.dialogxdemo.custom.recycleview.CustomRecycleView
        android:id="@+id/recycleView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:tag="ScrollController">
    </com.kongzue.dialogxdemo.custom.recycleview.CustomRecycleView>
</LinearLayout>
List<CustomRecycleViewAdapter.Data> list = new ArrayList<>();
list.add(new CustomRecycleViewAdapter.Data("Item Text 1"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 2"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 3"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 4"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 5"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 6"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 7"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 8"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 9"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 10"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 11"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 12"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 13"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 14"));

DialogX.globalStyle = MaterialStyle.style();
BottomDialog.build()
        .setCustomView(new OnBindView<BottomDialog>(R.layout.layout_custom_recycleview) {
    
    
            @Override
            public void onBind(BottomDialog dialog, View v) {
    
    
                RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.recycleView);
                LinearLayoutManager layoutManager = new LinearLayoutManager(me);
                recyclerView.setLayoutManager(layoutManager);
                CustomRecycleViewAdapter adapter = new CustomRecycleViewAdapter(list);
                recyclerView.setAdapter(adapter);
            }
        })
        .show();

ここに画像の説明を挿入

カスタムダイアログ

CustomDialog.show(new OnBindView<CustomDialog>(R.layout.layout_custom_dialog) {
    
    
            @Override
            public void onBind(final CustomDialog dialog, View v) {
    
    
                ImageView btnOk = v.findViewById(R.id.btn_ok);
                btnOk.setOnClickListener(new View.OnClickListener() {
    
    
                    @Override
                    public void onClick(View v) {
    
    
                        dialog.dismiss();
                    }
                });
            }
        })
        .setMaskColor(getResources().getColor(R.color.black30));

ここに画像の説明を挿入

ダイアログはボタン上に表示されます

CustomDialog.show(new OnBindView<CustomDialog>(R.layout.layout_custom_dialog_align) {
    
    
            private TextView btnSelectPositive;
            @Override
            public void onBind(final CustomDialog dialog, View v) {
    
    
                btnSelectPositive = v.findViewById(R.id.btn_selectPositive);
                btnSelectPositive.setOnClickListener(new View.OnClickListener() {
    
    
                    @Override
                    public void onClick(View v) {
    
    
                        PopTip.show("我知道了");
                        dialog.dismiss();
                    }
                });
            }
        })
        .setCancelable(false)
        .setMaskColor(getResources().getColor(R.color.black30))
        .setEnterAnimResId(R.anim.anim_custom_pop_enter)
        .setExitAnimResId(R.anim.anim_custom_pop_exit)
        .setAlignBaseViewGravity(view, Gravity.TOP) //显示在view上
        .setBaseViewMarginBottom(-dip2px(45))
        .show();

ここに画像の説明を挿入

他にもたくさんの機能がありますので、ぜひお試しください。

オープン ソース アドレス: https://github.com/kongzue/DialogX

My Github: github.com/yutils
My CSDN: https://blog.csdn.net/Yu1441
Weibo に注目してくれてありがとう: Ruojing in the rain
My QQ: 3373217 (技術交換可能)

おすすめ

転載: blog.csdn.net/Yu1441/article/details/127069177