自定义AlertDialog的样式

一、在XML中定义好要显示的AlertDialog的布局

二、在代码中创建alertdialog 对象

AlertDialog dialog = new AlertDialog.Builder(this).create();

调用show方法显示

 dialog.show();

三、设置 AlertDialog窗体的大小

dialog.getWindow().setGravity(Gravity.CENTER);

dialog.getWindow().setLayout((int)(width/1.5), LayoutParams.WRAP_CONTENT);

点击输入框时用来显示软键盘
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

显示布局
dialog.getWindow().setContentView(roleAlertLayout);

当单击外层布局时隐藏软键盘

layout.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
InputMethodManager imm = (InputMethodManager)getSystemService(PageRole.this.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(roleEdit.getWindowToken(), 0);
}
});

时间: 2024-12-25 03:40:05

自定义AlertDialog的样式的相关文章

Android中自定义下拉样式Spinner

Android中自定义下拉样式Spinner 本文继续介绍android自定义控件系列,自定义Spinner控件的使用. 实现思路 1.定义下拉控件布局(ListView及子控件布局) 2.自定义SpinerPopWindow类 3.定义填充数据的Adapter 效果图 一.定义控件布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http:/

AlertDialog.Builder 样式设置

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom)); 然后自定义自己的样式就可以了<?xml version="1.0" encoding="utf-8"?> <resources>     <style name="AlertDialogCustom&qu

Android之自定义AlertDialog和PopupWindow实现(仿微信Dialog)

我们知道,在很多时候,我们都不用Android内置的一些控件,而是自己自定义一些自己想要的控件,这样显得界面更美观. 今天主要是讲自定义AlertDialog和popupWindow的使用,在很多需求中,我们往往需要这样一个功能,就是点击一个按钮或者其它控件,弹出一个对话框,让用户可以在这个对话框中做一些事,比如输入.选择.提示.....等等,那么,这个弹出对话框的功能我们都知道可以用popupWindow和AlertDialog实现,的却,popupWindow被称为万能的,因为它的布局都是我

Android自定义进度条样式

最近在做一个widget,上面需要一个progressbar,产品经理和设计师给出来的东西是要实现一个圆角的progress和自定义的颜色,研究一小下,分享出来给大家哦. 测试于:Android4.0+ 操作步骤: 1.创建你的layout文件引用progressbar如下,标红处引用你自定的样式: <ProgressBar android:id="@+id/progressDownload" style="?android:attr/progressBarStyleH

[原创] Android 自定义AlertDialog 去黑边终极解决方案(亲测有效!)

问题:自定义AlertDialog出现黑边 运行代码段: View view = View.inflate(context, R.layout.dialog_common, null); mDialog = new AlertDialog.Builder(context).create(); mDialog.setView(view); mDialog.show(); dialog_common.xml <?xml version="1.0" encoding="utf

自定义AlertDialog(圆角+退出动画+自定义布局)

图片省略了不上传了... 首先看activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="ma

自定义AlertDialog(仿微信)

安卓自定义AlertDialog,原理很简单: AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).create(); dialog.show(); Window window = dialog.getWindow(); window.setContentView(R.layout.alert_dialog); 通过window设置自定义dialog布局: 效果如图: 主界面MainActivity代码: package

Android 自定义AlertDialog 去黑边终极解决方案(亲测有效!)

问题:自定义AlertDialog出现黑边 运行代码段: View view = View.inflate(context, R.layout.dialog_common, null); mDialog = new AlertDialog.Builder(context).create(); mDialog.setView(view); mDialog.show(); dialog_common.xml <?xml version="1.0" encoding="utf

jQuery Validate 表单验证插件----自定义校验结果样式

一.下载依赖包 网盘下载:https://yunpan.cn/cryvgGGAQ3DSW  访问密码 f224 二.引入依赖包 <script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script> <script src="lib/jquery.validate.js" type="text/javascript"