AlertDialog自定义View的用法+如何改变弹出框的大小
2014-07-11 11:59
405 查看
android系统定义了弹出框,支持我们自定义布局:
效果图是:
还有一种常见的样式是:
效果图是:
如果想改变Dialog的大小可以这样写:
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中edittext无法弹出问题
- AlertDialog的自定义View以及弹出后的亮度控制
- AlertDialog中使用自定义View中的点击监听如何实现
- AlertDialog中使用自定义View,其中的Button如何设置点击事件监听
- Android 改变AlertDialog中View字体的大小
- AlertDialog自定义view
- Android AlertDialog 方法setView(view,0,0,0,0)开发自定义对话框
- 如何自定义UIPickerView中文本的大小和文本靠左或靠右显示?
- ListView动态更新,弹出AlertDialog设置,然后在View上更新
- 按钮事件弹出多个AlertDialog,如何处理?
- 如何写自定义的AlertView
- 如何设定视频图像窗口大小并添加自定义View
- AlertDialog_对话框_最全用法详解_自定义布局和适配器
- 自定义Dialog用于电话咨询,具有从底部弹出效果,点击按钮改变颜色
- view上创建dialog,如何让dialog自动适应view的大小
- 如何对自定义的Dialog的View中控件进行监听
- UE如何改变点击上传图片的弹出框的大小...
- 如何设定视频图像窗口大小并添加自定义View
- 如何动态改变ImageView大小 -- 方案之二
- android:自定义layout动态改变view位置和大小