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);
AlertDialog自己定义View的使用方法+怎样改变弹出框的大小的更多相关文章
- VUX的使用方法(以弹出框为例)
一.安装 cnpm install vux --save cnpm install vux-loader --save-dev 二.配置 const vuxLoader = require('vux- ...
- Android自己定义View的实现方法
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/17357967 不知不觉中,带你一步步深入了解View系列的文章已经写到第四篇了.回 ...
- 练习PopupWindow弹出框之实现界面加载的时候显示弹出框到指定的view下面--两种延迟方法
今天在练习PopupWindow弹出框的时候,打算在界面加载的时候将弹出框展现出来并显示在指定的view下面. 初步方法是直接在OnResume方法里面直接执行showPopupWindows方法. ...
- android 自定义弹出框AlertDialog ,很炫的哦
于是就小小的模仿了下自己写了这个这样的效果,主要代码如下:dlg = new AlertDialog.Builder(context).create();dlg.show();dlg.getWin ...
- 将angular-ui-bootstrap的弹出框定义成一个服务的实践
定义一个弹出框的服务:alert_boxdefiine(["app"],function(mainapp){ mainapp.controller('ModalInstanceCt ...
- Android--自定义弹出框-自定义dialog
项目要用到弹出框,还要和苹果的样式一样(Android真是没地位),所以就自己定义了一个,不是很像(主要是没图),但是也还可以. 废话不多说了,直接上代码 1.先看布局文件 <?xml vers ...
- angular-ui-bootstrap的弹出框定义成一个服务的实践(二)
定义一个弹出框的服务:alert_box defiine(["app"],function(mainapp){ mainapp.controller('ModalInstanceC ...
- layer弹出框插件参数及方法介绍
layerui下载:http://www.layui.com 更多参数请阅读开发文档:http://www.layui.com/doc/modules/layer.html Layui 是一款采用自身 ...
- UniGui的信息弹出框MessageDlg自定义标题的方法(使用JS动态本地化文本)
UniGui的信息弹出框MessageDlg的原型定义如下: procedure MessageDlg(const Msg: string; DlgType: TMsgDlgType; Buttons ...
随机推荐
- Git 工具 - 子模块
子模块 有种情况我们经常会遇到:某个工作中的项目需要包含并使用另一个项目. 也许是第三方库,或者你独立开发的,用于多个父项目的库. 现在问题来了:你想要把它们当做两个独立的项目,同时又想在一个项目中使 ...
- 使用Eric构建Caffe应用程序-Baby年龄识别
训练好的Caffe网络结构,可以固定下来,直接载入程序作为数据库接口使用.本文使用Eric构建运行于Python环境下的图片识别应用程序,因为Eric使用QT作为GUI,且有Python的接口,可直接 ...
- 还是UVa340
#include<stdio.h> #define maxn 1010 int main() { int num,a[maxn],i,j,b[maxn]; ; &&num) ...
- Java入门第一季——从此投身Java??
找工作告一段落. 最后的工作呢,和java紧密相关,也是阴差阳错,不过都是软件开发,都好了,不过以后侧重点肯定是在java这边,php有机会还是一直学下去的,那么美的说~ Java开发第一季 一.简 ...
- 原生sql的各种问题
1.nutz有方法自动根据数据库建models吗?2.select * from a a没有建相应的models怎么取结果?3.可以直接操作result,而不是在callback里面设置吗? wend ...
- CGContext与上下文
上下文指的是场景拥有的资源或属性. 上下文的操作包含上下文的设置: 和上下文的引用. 上下文是一个结构体. 主要包含结构体的设置和使用.
- jdbc转账操作
public class cs{ public static void main(String[] args){ try{ Connection conn=JdbcUtils.getConnectio ...
- Fear No More歌词
"Fear No More" Every anxious thought that steals my breath It's a heavy weight upon my ...
- 前端自动化构建yeoman
前端自动化可分为: yo(脚手架工具).grunt(构建工具).bower(包管理器). OMAN的特性 http://yeoman.io/learning/ 闪电般的初始化:项目开始阶段,可以基 ...
- day03深浅拷贝、文件操作和函数初识
一.赋值.浅拷贝与深拷贝 直接赋值:其实就是对象的引用(别名). 浅拷贝(copy):拷贝父对象,不会拷贝对象的内部的子对象. 深拷贝(deepcopy): copy 模块的 deepcopy 方法, ...