android系统定义了弹出框,支持我们自己定义布局:

	public AlertDialog getEditCustomDialog() {
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.custom_message_rename, null);
AlertDialog.Builder builder = new AlertDialog.Builder(AnimationTest.this);
builder.setView(view);
builder.setTitle("A New Version is Available");
return builder.create();
}
<?

xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <EditText
android:id="@+id/rc_document_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:imeOptions="flagNoEnterAction"
android:inputType="textNoSuggestions"
android:maxLines="5"
android:textColor="#000000"
android:textSize="@dimen/font_size_medium" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="? android:attr/dividerHorizontal" /> <LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:measureWithLargestChild="true"
android:orientation="horizontal"
android:padding="0dp" > <Button
android:id="@+id/cancelBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground"
android:text="Cancel" /> <View
android:id="@+id/postCancelBtnDivider"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="?android:attr/dividerHorizontal" /> <Button
android:id="@+id/okBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="? android:attr/selectableItemBackground"
android:text="OK" />
</LinearLayout> </LinearLayout>

效果图是:

另一种常见的样式是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="60dp" > <TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="60dp"
android:layout_marginLeft="25dp"
android:text="@string/upgrade_content"
android:textColor="#000000"
android:textSize="22sp" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@id/content"
android:orientation="horizontal" > <CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:text="@string/remind_me"
android:textColor="#000000"
android:textSize="14sp" />
</LinearLayout> </RelativeLayout>

效果图是:

假设想改变Dialog的大小能够这样写:

	<span style="white-space:pre">				</span>AlertDialog dialog = getCustomDialog();
dialog.show(); //一定得在show完dialog后来set属性
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.width = AnimationTest.this.getResources().getDimensionPixelSize(R.dimen.dialog_width);
lp.height = AnimationTest.this.getResources().getDimensionPixelSize(R.dimen.dialog_height);
dialog.getWindow().setAttributes(lp);

AlertDialog自己定义View的使用方法+怎样改变弹出框的大小的更多相关文章

  1. VUX的使用方法(以弹出框为例)

    一.安装 cnpm install vux --save cnpm install vux-loader --save-dev 二.配置 const vuxLoader = require('vux- ...

  2. Android自己定义View的实现方法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/17357967 不知不觉中,带你一步步深入了解View系列的文章已经写到第四篇了.回 ...

  3. 练习PopupWindow弹出框之实现界面加载的时候显示弹出框到指定的view下面--两种延迟方法

    今天在练习PopupWindow弹出框的时候,打算在界面加载的时候将弹出框展现出来并显示在指定的view下面. 初步方法是直接在OnResume方法里面直接执行showPopupWindows方法. ...

  4. android 自定义弹出框AlertDialog ,很炫的哦

      于是就小小的模仿了下自己写了这个这样的效果,主要代码如下:dlg = new AlertDialog.Builder(context).create();dlg.show();dlg.getWin ...

  5. 将angular-ui-bootstrap的弹出框定义成一个服务的实践

    定义一个弹出框的服务:alert_boxdefiine(["app"],function(mainapp){ mainapp.controller('ModalInstanceCt ...

  6. Android--自定义弹出框-自定义dialog

    项目要用到弹出框,还要和苹果的样式一样(Android真是没地位),所以就自己定义了一个,不是很像(主要是没图),但是也还可以. 废话不多说了,直接上代码 1.先看布局文件 <?xml vers ...

  7. angular-ui-bootstrap的弹出框定义成一个服务的实践(二)

    定义一个弹出框的服务:alert_box defiine(["app"],function(mainapp){ mainapp.controller('ModalInstanceC ...

  8. layer弹出框插件参数及方法介绍

    layerui下载:http://www.layui.com 更多参数请阅读开发文档:http://www.layui.com/doc/modules/layer.html Layui 是一款采用自身 ...

  9. UniGui的信息弹出框MessageDlg自定义标题的方法(使用JS动态本地化文本)

    UniGui的信息弹出框MessageDlg的原型定义如下: procedure MessageDlg(const Msg: string; DlgType: TMsgDlgType; Buttons ...

随机推荐

  1. 机器学习——SVM讲解

    支持向量机(Support Vector Machine) SVM是一类按监督学习方式对数据进行二元分类的广义线性分类器,决策边界是对学习样本求解的最大边距超平面.只需要知道,SVM是一个有监督的分类 ...

  2. POJ 1200 Hash

    我的hash从来没写对过........ (白学了快一年OI --原来连个hash都没写对过) 但是 但是 今天是一个值得纪念的日子. 看看标题 我竟然在写hash的题解. (好了好了 废话少说) 题 ...

  3. awk杂集-20170911

    awk 格式 1.awk -F '分割符' 'BEGIN{} /执行条件/{} END{}' filepath; 默认使用空格分割 2.awk -v word=$command '{print wor ...

  4. lua 计算字符串字符个数“中文字算一个字符”

    local function GetStringWordNum(str) local fontSize = local lenInByte = #str local count = local i = ...

  5. js---通过arguments来获取指定参数

    通过访问arguments对象的length属性可以获取有多少个参数传递给了函数. 如:每次被调用的时候,输出传入其中的参数个数 function doAdd(){ alert(arguments.l ...

  6. 全能VIP音乐在线解析

    浏览器安装暴力猴扩展即可使用 // ==UserScript== // @name 全能VIP音乐在线解析 // @version 0.0.10 // @homepage https://greasy ...

  7. Teamwork-六月上旬心得体会

    六月上旬心得体会 在五月末的时候,老师针对我们团队的状况提出了几点建议和解决方案,而这半个月里,我们尝试性地运用了其中的几件工具与方法. 1.燃尽图与每日总结 我们采用的是<构建之法>书中 ...

  8. sql server restore DB issue

    error occurs when restoring the backup file of sql server(DB.bak) to run the above t-sql will shoot ...

  9. js 按钮连击 减少触发事件次数

    <body> <input type="button" onClick="testbtn()" value="测试按钮"& ...

  10. input[type=radio]选中的样式变化

    input[type=radio]:hover{ border: 2px solid #D0D0D0; } input[type=radio]:focus{ border: 2px solid #1B ...