短視訊系統原始碼,點選選擇框,底部彈出可以選擇的選項

zhibo系統開發發表於2021-12-31

短視訊系統原始碼,點選選擇框,底部彈出可以選擇的選項實現的相關程式碼

匯入依賴:

implementation 'com.lxj:xpopup:1.9.0'
 
implementation 'com.contrarywind:Android-PickerView:4.1.9'
 
public class DialogHelper {
 
    public static void showConfirmDialog(Context context, String title, CharSequence content,
                                         CharSequence cancelText, CharSequence confirmText, OnConfirmListener listener, OnCancelListener cancelListener) {
        ConfirmDialog confirmDialog = new ConfirmDialog(context)
                .setCancelText(cancelText)
                .setConfirmText(confirmText)
                .setTitleContent(title, content, null)
                .setListener(listener, cancelListener);
        new XPopup.Builder(context)
                .setPopupCallback(new SimpleCallback())
                .isCenterHorizontal(true)
                .asCustom(confirmDialog)
                .show();
    }
 
    public static void showConfirmDialog(Context context, String title, CharSequence content,
                                         boolean isHideCancel, OnConfirmListener listener) {
        ConfirmDialog confirmDialog = new ConfirmDialog(context)
                .setCancelText(context.getString(R.string.cancel))
                .setConfirmText(context.getString(R.string.text_sure))
                .setTitleContent(title, content, null)
                .setListener(listener, null);
        if (isHideCancel) confirmDialog.hideCancelBtn();
 
        new XPopup.Builder(context)
                .setPopupCallback(new SimpleCallback())
                .isCenterHorizontal(true)
                .asCustom(confirmDialog)
                .show();
    }
 
    public static void showConfirmDialog2(Context context, String title, CharSequence content, OnConfirmListener listener) {
        ConfirmDialog confirmDialog = new ConfirmDialog(context)
                .setCancelText(context.getString(R.string.cancel))
                .setConfirmText(context.getString(R.string.close_dialog))
                .setTitleContent(title, content, null)
                .setListener(listener, null);
        confirmDialog.hideCancelBtn();
 
        new XPopup.Builder(context)
                .setPopupCallback(new SimpleCallback())
                .isCenterHorizontal(true)
                .asCustom(confirmDialog)
                .show();
    }
 
    public static void showConfirmDialog(Context context, String title, CharSequence content,
                                         OnConfirmListener listener, OnCancelListener cancelListener) {
        ConfirmDialog confirmDialog = new ConfirmDialog(context)
                .setCancelText(context.getString(R.string.cancel))
                .setConfirmText(context.getString(R.string.text_sure))
                .setTitleContent(title, content, null)
                .setListener(listener, cancelListener);
        new XPopup.Builder(context)
                .setPopupCallback(new SimpleCallback())
                .isCenterHorizontal(true)
                .asCustom(confirmDialog)
                .show();
    }
 
    public static BasePopupView showConfirmDialog(Context context, String title, CharSequence content, OnConfirmListener listener) {
        ConfirmDialog confirmDialog = new ConfirmDialog(context)
                .setCancelText(context.getString(R.string.cancel))
                .setConfirmText(context.getString(R.string.text_sure))
                .setTitleContent(title, content, null)
                .setListener(listener, null);
        return new XPopup.Builder(context)
                .dismissOnTouchOutside(false)
                .dismissOnBackPressed(false)
                .setPopupCallback(new SimpleCallback())
                .asCustom(confirmDialog)
                .show();
    }
 
    public static void showOptionPicker(Context context, String title, List<String> list, OnOptionsSelectListener listener) {
        OptionsPickerView<String> pvOptions = new OptionsPickerBuilder(context, listener)
                .setTitleText(title)
                .setTitleSize(14)
                .setSubCalSize(14)
                .setContentTextSize(16)//設定滾輪文字大小
                .setDividerColor(Color.LTGRAY)//設定分割線的顏色
//                .setSelectOptions(0, 1)//預設選中項
                .setBgColor(Color.WHITE)
                .setTitleBgColor(Color.WHITE)
                .setTitleColor(Color.BLACK)
                .setSubmitColor(Color.rgb(255, 117, 105))
                .setCancelColor(Color.rgb(153, 153, 153))
                .setTextColorCenter(Color.BLACK)
                .setCyclic(false, false, false)
                .isRestoreItem(false)//切換時是否還原,設定預設選中第一項。
                .isCenterLabel(true) //是否只顯示中間選中項的label文字,false則每項item全部都帶有label。
//                .setBackgroundId(0x00000000) //設定外部遮罩顏色
                .build();
        pvOptions.setPicker(list);//一級選擇器
        pvOptions.show();
    }
 
    public static void showOptionPicker(Context context, String title, List<String> list, int option1, OnOptionsSelectListener listener) {
        OptionsPickerView<String> pvOptions = new OptionsPickerBuilder(context, listener)
                .setTitleText(title)
                .setTitleSize(14)
                .setSubCalSize(12)
                .setContentTextSize(14)//設定滾輪文字大小
                .setDividerColor(Color.LTGRAY)//設定分割線的顏色
                .setSelectOptions(option1)//預設選中項
                .setBgColor(Color.WHITE)
                .setTitleBgColor(Color.WHITE)
                .setTitleColor(Color.BLACK)
                .setSubmitColor(Color.rgb(255, 117, 105))
                .setCancelColor(Color.rgb(153, 153, 153))
                .setTextColorCenter(Color.BLACK)
                .setCyclic(false, false, false)
                .isRestoreItem(false)//切換時是否還原,設定預設選中第一項。
                .isCenterLabel(true) //是否只顯示中間選中項的label文字,false則每項item全部都帶有label。
//                .setBackgroundId(0x00000000) //設定外部遮罩顏色
                .build();
        pvOptions.setPicker(list);//一級選擇器
        pvOptions.show();
    }
 
    /**
     * Dialog 模式下,在底部彈出
     *
     * @param context
     * @param title
     * @param listener
     */
    public static void showTimePicker(Context context, String title, OnTimeSelectListener listener) {
        //系統當前時間
        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        startDate.set(2000, 0, 1);
        Calendar endDate = Calendar.getInstance();
        TimePickerView mTimePickerView;
        mTimePickerView = new TimePickerBuilder(context, listener)
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .setTitleText(title)
                .setTitleSize(14)
                .setSubCalSize(12)
                .setContentTextSize(14)
                .setDividerColor(Color.LTGRAY)//設定分割線的顏色
                .setBgColor(Color.WHITE)
                .setTitleBgColor(Color.WHITE)
                .setTitleColor(Color.rgb(51, 51, 51))
                .setSubmitColor(Color.rgb(255, 117, 105))
                .setCancelColor(Color.rgb(153, 153, 153))
                .setTextColorCenter(Color.rgb(51, 51, 51))
                .setType(new boolean[]{true, true, true, false, false, false})
                .isCyclic(false)
                .isDialog(true)
                .build();
        Dialog mDialog = mTimePickerView.getDialog();
        if (mDialog != null) {
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.BOTTOM);
 
            params.leftMargin = 0;
            params.rightMargin = 0;
            mTimePickerView.getDialogContainerLayout().setLayoutParams(params);
            Window dialogWindow = mDialog.getWindow();
            if (dialogWindow != null) {
                dialogWindow.setWindowAnimations(R.style.picker_view_slide_anim);//修改動畫樣式
                dialogWindow.setGravity(Gravity.BOTTOM);//改成Bottom,底部顯示
            }
        }
        mTimePickerView.show();
    }
 
 
    public static void showPasswordDialog(Context mContext, String title, String content, String inputContent, String hint, OnInputConfirmListener listener) {
 
        new XPopup.Builder(mContext)
                //.dismissOnBackPressed(false)
                .autoOpenSoftInput(true)
//                        .autoFocusEditText(false) //是否讓彈窗內的EditText自動獲取焦點,預設是true
                .isRequestFocus(false)
                .isCenterHorizontal(true)
                //.moveUpToKeyboard(false)   //是否移動到軟鍵盤上面,預設為true
                .asInputConfirm(title, content, inputContent, hint, listener)
                .bindLayout(R.layout.dialog_password_confirm)
                .show();
    }
 
 
}


使用:

showConfirmDialog("系統提示", "確定退出嗎?", this::finish);
 
 
showConfirmDialog("系統提示", "確定退出嗎?", ()->{});
 
 
List<String> productName = new ArrayList<>();
DialogHelper.showOptionPicker(mActivity, "列表選擇", productName, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    
            }
        });


以上就是短視訊系統原始碼,點選選擇框,底部彈出可以選擇的選項實現的相關程式碼, 更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2850312/,如需轉載,請註明出處,否則將追究法律責任。

相關文章