android Dialog提示框。单选项dialog,多选项dialog,EditText键盘不弹出

AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setMessage("You have system write settings permission now.");
alertDialog.show();

 

 

private void showNormalDialogOne() {
    /* @setIcon 设置对话框图标
     * @setTitle 设置对话框标题
     * @setMessage 设置对话框消息提示
     * setXXX方法返回Dialog对象,因此可以链式设置属性
     */
    final AlertDialog.Builder normalDialog = new AlertDialog.Builder(this);
    normalDialog.setTitle("提示");
    normalDialog.setMessage("确定删除所有!");
    normalDialog.setPositiveButton("确定",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                   // delehistory();//dosomething
                }
            });
    normalDialog.setNegativeButton("取消",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
    normalDialog.show();
}

单选项dialog

AlertDialog.Builder builder = new AlertDialog.Builder(SynthActivity.this, android.R.style.Theme_Holo_Light_Dialog);
builder.setTitle("引擎空闲时切换");
final Map<String, String> map = new LinkedHashMap<>(4);
map.put("离线女声", OfflineResource.VOICE_FEMALE);
map.put("离线男声", OfflineResource.VOICE_MALE);
map.put("离线度逍遥", OfflineResource.VOICE_DUXY);
map.put("离线度丫丫", OfflineResource.VOICE_DUYY);
final String[] keysTemp = new String[4];
final String[] keys = map.keySet().toArray(keysTemp);
builder.setItems(keys, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        loadModel(map.get(keys[which]));
        Log.i("lgq","....."+map.get(keys[which]));
    }
});
builder.show();

2、多选项dialog

private String[] favor = {"美容  ", "汽车  ", "游戏  ", "社交  ", "体育  ", "阅读  ",
        "影视  ", "母婴  ", "健康  ", "家居  ", "服饰  ", "其他  "};
private String hobby;
private int befoid;
    //兴趣爱好设置
    private void hobbySetting() {
        AlertDialog.Builder dialogm = new AlertDialog.Builder(this);
        dialogm.setMultiChoiceItems(favor, new boolean[]{false, false, false, false, false, false, false, false, false, false, false, false},
                new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                        if (!TextUtils.isEmpty(hobby)&&hobby.split("\\  ").length > 2&&befoid!=which) {
//                            ToastUtil.centralToast("最多只能选择3项", mContext);
                            dialog.dismiss();
                            hobby = "";
                            befoid = 99;
                        } else {
                            if (isChecked){
                                hobby = hobby + favor[which];
                                befoid = which;
                                Log.v("lgq","兴趣爱好。。。。。-====="+hobby);
                            }
                            else {
                                hobby = hobby.replace(favor[which], "");
                                befoid = 99;
                                Log.v("lgq","兴趣爱好。。。else。。==="+hobby);
                            }
                        }
                    }
                });
        dialogm.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                if (hobby.equals("")) tvHobby.setText("未设置");
                else tvHobby.setText(hobby);
                hobby = "";
            }
        });
        dialogm.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

            }
        });
        dialogm.show();
    }

默认提示框

public class DialogUtils {

    //自定义View对话框
    public static Dialog show(Context context, View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context)
                .setView(view)
                .setCancelable(true);
        Dialog dialog = builder.show();
        dialog.getWindow().getDecorView().setBackground(null);
        return dialog;
    }

}

调用

//软件说明对话框
public void showDescription() {
    View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_description, null);
    //软件说明
    Button btnDismiss = view.findViewById(R.id.btn_dismiss);
    mTxvModeChoose = view.findViewById(R.id.txv_mode_choose);

    final Dialog dialog = DialogUtils.show(mContext, view);
    btnDismiss.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //点击右上角 × 关闭弹窗
            dialog.dismiss();
        }
    });
    mTxvModeChoose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //点击选择模式
            mTxvModeChoose.setBackgroundResource(R.drawable.txv_stroke);
            mTxvModeFill.setBackground(null);
            mTxvDictionary.setBackground(null);
            mTxvDescription.setText(R.string.str_descrip_choose);
        }
    });


}

 点击事件Dialog

public class TipDialog2 extends Dialog {
    @BindView(R.id.Cancel_tv)
    TextView mCancelTv;
    @BindView(R.id.confirm_tv)
    TextView mConfirmTv;
    @BindView(R.id.tv_content)
    TextView mTvContent;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    private CallBack mCallBack;

    public TipDialog2(@NonNull Context context) {
        super(context, R.style.CommonDialogStyle);
        setContentView(R.layout.dialog_tip2);
        ButterKnife.bind(this);
    }

    @OnClick({ R.id.Cancel_tv, R.id.confirm_tv })
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.Cancel_tv:
                dismiss();
                break;
            case R.id.confirm_tv:
                if (mCallBack != null) {
                    mCallBack.confirm();
                }
                dismiss();
                break;
        }
    }

    public void setCallBack(CallBack callBack) {
        this.mCallBack = callBack;
    }

    public interface CallBack {
        void confirm();
    }

    public void setTitle(boolean isVisible,String title){
        mTvTitle.setVisibility(isVisible?View.VISIBLE:View.GONE);
        mTvTitle.setText(title);
    }
    public void setTvContent(String content) {
        mTvContent.setText(content);
    }
}

调用

TipDialog2 tipDialog2 = new TipDialog2(this);
tipDialog2.setCallBack(new TipDialog2.CallBack() {
    @Override
    public void confirm() {
        finish();
    }
});
tipDialog2.show();

EditText键盘不弹出 

//弹出软键盘
public void showKeyboard(EditText editText) {
    //其中editText为dialog中的输入框的 EditText
    if(editText!=null){
        //设置可获得焦点
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        //请求获得焦点
        editText.requestFocus();
        //调用系统输入法
        InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(editText, 0);
    }
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值