AlertDialog custom View usage + how to change the size of the pop-up box, alertdialogview

Source: Internet
Author: User

AlertDialog custom View usage + how to change the size of the pop-up box, alertdialogview

The pop-up box for android system definition supports custom Layout:

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>

Yes:

 



Another common style is:

<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>

Yes:



If you want to change the Dialog size, you can write as follows:

<Span style = "white-space: pre"> </span> AlertDialog dialog = getCustomDialog (); dialog. show (); // you must set the WindowManager attribute after show dialog. 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 );



How does android AlertDialog set the Tile size and color? And the background of the AlertDialog dialog box?

We recommend that you use the custom xml layout and then use the setView () method for this dialog box. The procedure is as follows:
1. Write a layout file, for example, dialog_layout.
2. Convert the layout file to the View component
LayoutInflater factory = LayoutInflater. from (your Activity );
View myView = factory. inflate (R. layout. dialog_layout, null );
3. Set it in the dialog box and directly use setView (myView) in the dialog box.

You can use the setIcon () method to modify the title size and color. Create a nice title in ps, copy it to the drawable folder, and then setIcon (R. drawable. titlePic.

In addition to alertdialog, what pop-up boxes does android have?

Dialog is the parent class of AlertDialog. AlertDialog can only be built through Builder. If Dialog is used, it has a great degree of freedom and can display any content you want to display. Example: dialog dialog = new Dialog (this); dialog. setContentView (view); dialog. show ();

In addition, there is a PopupWindow. For example, the pop-up menu item is implemented using it. Compared with Dialog, the biggest advantage is that it can be precisely located where you want it to be displayed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.