AlertDialog自己定义View的使用方法+怎样改变弹出框的大小

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);
时间: 2024-08-07 16:58:39

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

AlertDialog自定义View的用法+如何改变弹出框的大小

android系统定义了弹出框,支持我们自定义布局: public AlertDialog getEditCustomDialog() { LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.custom_message_rename, null); AlertDialog.Builder builder = new AlertDialog.Builder(AnimationTe

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

今天在练习PopupWindow弹出框的时候,打算在界面加载的时候将弹出框展现出来并显示在指定的view下面. 初步方法是直接在OnResume方法里面直接执行showPopupWindows方法. 但是报“Unable to add window -- token null is not valid; is your activity running?” 原因参考:http://cb269267.iteye.com/blog/1787779 总结下原因如下:popupwindow必须要指定一个

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

于是就小小的模仿了下自己写了这个这样的效果,主要代码如下:dlg = new AlertDialog.Builder(context).create();dlg.show();dlg.getWindow().setContentView(R.layout.alert_style);LayoutInflater factory = LayoutInflater.from(context);View view = factory.inflate(R.layout.alert_style, null)

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

项目要用到弹出框,还要和苹果的样式一样(Android真是没地位),所以就自己定义了一个,不是很像(主要是没图),但是也还可以. 废话不多说了,直接上代码 1.先看布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_wi

面遮罩弹出框已经不是一个陌生的话题了,实现的方法大同小异多种多样,今天用jQuery实现页面遮罩弹出

页面遮罩弹出框是最常见的一种情况,今天用jQuery实现页面遮罩弹出框,主要用的技术有JQuery,css和html, html代码如下: 复制代码代码如下: <div id="main"><a href="javascript:showBg();">点击这里查看效果</a> <div id="fullbg"></div> <div id="dialog">

Visual Studio 打开解决方案后 弹出框显示 &quot;正在打开文件...&quot; 迟迟没反应 的解决方法

Visual Studio 打开解决方案后 弹出框显示 "正在打开文件...",任务管理器的devenv进程又很正常,不会显示"未响应". 而IDE的左下角有个 "正在等待分析完成..." 提示. 刚开始,我以为是VS插件问题,因为我刚安装了一个插件后,重启VS,打开解决方案就出现这个问题了,所以我以为是VS插件问题. 后来我把VS插件通通卸载了,把/ResetAddin /ResetSkipPkgs /ResetSettings 之类的deve

弹出框,添加出行人员,追加提交方法,H5检查OK再调用ajax提交到controller

01传递参数,显示或者隐藏弹出框 /*start 显示和隐藏遮罩*/ function controlShade(date){ if(date == 's'){ $(".mask").show(); $(".maskbox").stop().animate({"margin-top":10+"px"},300); }else if(date == 'h'){ $(".maskbox").stop().ani

QTP录制后弹出框一个或多个ActiveX控件无法显示的解决方法

制一段脚本代码,在专家视图窗口中编辑录制的脚本代码时,会碰到弹出一个对话窗口,提示为"当前安全设置禁止运行该页中的ActiveX 控件,因此,该页可能无法正常显示"类似的东西,而在人工操作时却没有这样的现象.(如图) 问题主要出在于QTP设置本身,之所以在编辑录制好的脚本时,QTP出现关于Active的对话提示窗口,问题在于QTP的设置,要消除该提示窗口.应对QTP作如下设置:toos–options–Active Screen–Advanced–点选Load ActiveX cont

java方法里面生成js弹出框

核心代码:方法参数要有response response.setContextType("text/html;charset=UTF-8"); PrintWrite out = response.getWrite(); out.write("<script type='text/javascript'>alert('这是一个弹出框!');window.close();</script>"); out.flush(); out.close();