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() {@Overridepublic void onClick(DialogInterface dialog, int which) {// delehistory();//dosomething}});normalDialog.setNegativeButton("取消",new DialogInterface.OnClickListener() {@Overridepublic 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() {@Overridepublic 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() {@Overridepublic 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() {@Overridepublic void onClick(DialogInterface dialog, int which) {dialog.dismiss();if (hobby.equals("")) tvHobby.setText("未设置");else tvHobby.setText(hobby);hobby = "";}});dialogm.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic 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() {@Overridepublic void onClick(View v) {//点击右上角 × 关闭弹窗dialog.dismiss();}});mTxvModeChoose.setOnClickListener(new View.OnClickListener() {@Overridepublic 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() {@Overridepublic void confirm() {finish();}
});
tipDialog2.show();

EditText键盘不弹出 

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415772.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

用C语言实现:判断1000-2000年之间的闰年。

在编程之前&#xff0c;首先我们要了解闰年的定义&#xff1a; 1、普通年能整除4且不能整除100的为闰年。2、世纪年能整除400的是闰年。 了解概念后&#xff0c;我们首先需要用for循环控制输入的年份&#xff0c;然后再循环内使用if语句判断上述的两个条件是否成立。 #include&…

eclipse/myeclipse中快捷键 Ctrl+shift+down/up 出现屏幕颠倒的解决方法

1.原因&#xff1a;快捷键被占用 2.解决 如果是被其它软件占用&#xff0c;则修改其它软件的快捷键。 查看快捷键是否被占用工具&#xff1a;http://download.csdn.net/download/muyeju/9999443    如果是Integer占用&#xff0c;则禁用快捷键&#xff0c;桌面右击->图形选…

mongoose 更新元素 DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany

我一开始的写法: const updOne await this.update({ _id: verify_id }, {$set: {// 认证通过&#xff0c;状态设置为1state: 1,// 审核操作人verify_user,verify_at: Date.now()} });使用mongoose更新元素值&#xff0c;报错了DeprecationWarning: collection.update is depr…

Git Bash下载安装,git命令下载项目,上传android项目到github步骤,以及取消项目关联Git,设置git忽略文件

设置忽略文件 1、工程下创建文件夹gitignore。push即可 *.iml .gradle /local.properties /.idea/caches /.idea/libraries /.idea/modules.xml /.idea/workspace.xml /.idea/navEditor.xml /.idea/assetWizardSettings.xml .DS_Store /build /captures .externalNativeBuild …

vue 获取验证码倒计时组件

之前写过一个计时函数&#xff0c;有计算误差&#xff0c;但是验证码的60秒倒计时可以忽略这一点点误差。直接上代码。 <template><div class"captcha-row"><input class"captcha-input" placeholder"输入验证码" auto-focus …

【iCore1S 双核心板_FPGA】例程十六:基于SPI的ARM与FPGA通信实验

实验现象&#xff1a; 核心代码&#xff1a; int main(void) {int i,n;char buffer[20];char spi_buffer[20];HAL_Init();system_clock.initialize();led.initialize();usart1.initialize(115200);spi.initialize();usart1.printf("Hello! I am iCore1S!\r\n"); …

记录一个奇葩问题 宝塔 nginx: [warn] conflicting server

宝塔面板里面运行很久的nginx&#xff0c;好久没有重启&#xff0c;这次一重启&#xff0c;报错了。 解决方法&#xff0c;去/www/server/panel/vhost/nginx目录下&#xff0c;把相关的历史记录给删掉&#xff0c;再重启&#xff0c;就没有问题了

小程序设置页面背景颜色

首先&#xff0c;我使用的是mpvue开发。样式使用的less&#xff0c;并且全局会定义一套主题。 primary-color : #ff8730; second-color : #F48B4A; background-color :#F3F3F3; second-text-color :#787878;.flex-center-row {display: flex;flex-d…