• 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);


  • 相关阅读:
    java系列: 在eclipse中调试时,输入的jsp或者servlet页面的地址要区分大小写
    Activiti系列: 如何在web中使用activiti和sql server
    Java系列:Add Microsoft SQL JDBC driver to Maven
    eclipse系列: Cannot change version of project facet Dynamic web的解决方法
    Java系列:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    Activiti系列:如何让Activiti-Explorer使用sql server数据库
    MySQL系列:查看并修改当前数据库的编码
    activiti-explorer:使用mysql导入外部bpmn文件后存在乱码的问题
    Activiti系列:如何把Activiti工程转换为maven工程以解决依赖项找不到的问题
    java从0开始学——数组,一维和多维
  • 原文地址:https://www.cnblogs.com/mthoutai/p/6939499.html
Copyright © 2020-2023  润新知