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,一经查实,立即删除!

相关文章

同一台机器上安装2个SDE服务

同一台机器上安装2个SDE服务环境&#xff1a;Windows Server 2008 R2 x64Oracle 10gArcSDE 9.3 适用于数据库中SDE表空间以及SDE用户已经创建。 1&#xff1a;拷贝C:\Program Files (x86)\ArcGIS\ArcSDE\目录下ora10gexe文件夹2份&#xff0c;分别命名ora10gexeA、ora10gexeB。…

node 微信开发 json转xml 格式

在微信开发中&#xff0c;大多请求接口格式需要传xml&#xff0c;所以提供一下微信适用的json转xml格式代码: json2Xml: (json) > {let _xml ;Object.keys(json).map((key) > {_xml <${key}>${json[key]}</${key}>})return <xml>${_xml}</xml>…

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

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

android 原生调用js,js调用原生

原生调用js方法&#xff0c;带参数 activityBaseWebAddWebView.loadUrl("javascript:changeColor(" viewColor ")");//changeColor是js方法&#xff0c;viewColor是参数 js调用原生 1、创建js通信接口 //js通信接口 class JavascriptInterface {…

关于测试中常用到的一些方法、策略总结

一些常用模块的测试用例 1、登录  2、添加  3、查询  4、删除 1、登录 ①用户名和密码都符合要求&#xff08;格式上的要求&#xff09; ②用户名和密码都不符合要求&#xff08;格式上的要求&#xff09; ③用户名符合要求&#xff0c;密码不符合要求&#xff08;格…

【BZOJ1976】[BeiJing2010组队]能量魔方 Cube 最小割

【BZOJ1976】[BeiJing2010组队]能量魔方 Cube Description 小C 有一个能量魔方&#xff0c;这个魔方可神奇了&#xff0c;只要按照特定方式&#xff0c;放入不同的 能量水晶&#xff0c;就可以产生巨大的能量。 能量魔方是一个 N*N*N 的立方体&#xff0c;一共用 N3 个空格可以…

android activity调用Adapter方法刷新列表UI,RecyclerView.Adapter

在adapter中创建被调用方法cleckAll public class JYfkleixinAdapter extends RecyclerView.Adapter<JYfkleixinAdapter.ViewHolder> {private Context context;private OnItemClickListener mOnItemClickListener;private List<JyfkEntity> entityList;public JY…

vuex 对象嵌套属性的修改 mutations set 很方便的写法

需求&#xff1a;一个对象 const state {user: {verify: {state: 0}} }我需要使用类似this.set({ user.verify.state: 1 })这种写法直接获取或修改state[user.verify.state]的值。不知道别人怎么写的&#xff0c;我的写法如下&#xff1a; const mutations {set(state, par…

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

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

android 获取图片主色调

在build.gradle添加依赖 compile com.github.florent37:glidepalette:1.0.6 使用 TextView tvColor(TextView) findViewById(R.id.testte); ImageView imageView (ImageView)findViewById(R.id.testimage); tvColor.setText(style); ImageManager.loadAndPalette(MainActivity…

基于B/S架构的故障模型

基于B/S架构的故障模型 基于&#xff22;/&#xff33;架构的软件进行的测试&#xff0c;主要进行的有功能测试、性能测试、安全性测试、配置和兼容性测试、可用性测试、安装部署测试、用户手册、在线帮助测试等。下列分别介绍这些测试的内容。 &#xff11;、 功能…

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…

mongodb $unwind 聚合管道

$unwind&#xff1a;将文档中的某一个数组类型字段拆分成多条&#xff0c;每条包含数组中的一个值。 需求&#xff1a; {"_id" : ObjectId("5951c5de567ebff0d5011fba"),"name" : "陈晓婵","address" : "北京朝阳区&q…

QC无法启动,实战记录

今天上午QC还用得好好的&#xff0c;下午就突然打不开了&#xff0c;急了&#xff0c;服务重启了一遍还是不行。最后将错误信息截下来&#xff0c;仔细研究&#xff0c;同时也要感谢测试群的朋友们的帮忙&#xff0c;终于找到了一些方向。 下面把错误信息贴出来&#xff1a; …

android butterknife使用详解

添加依赖 compile com.jakewharton:butterknife:8.6.0 annotationProcessor com.jakewharton:butterknife-compiler:8.6.0 //下载最新黄油刀 implementation com.jakewharton:butterknife:10.2.0 annotationProcessor com.jakewharton:butterknife-compiler:10.2.0 …

工作108:swiper使用

<!--首页管理--> <template><div><el-card><h1>等待处理</h1><div style"width: 100%;height: 200px"><swiper ref"mySwiper" ><swiper-slide v-for"(item,index) in task"><el-butt…