Android advanced AlertDialog custom, androidalertdialog
AlertDialog can be customized in many ways. Here we will introduce two methods.
The first type is relatively simple, with only custom content.
The following six methods are described in detail in AlertDialog.
1. Simple AlertDialog (only a simple piece of information is displayed, such as about us)
2. AlertDialog with buttons (display prompt information for user operations, such as the warning box at exit)
3. Similar to ListView's AlertDialog (display content, such as some registration information of someone)
4. AlertDialog similar to RadioButton)
5. AlertDialog similar to CheckBox (allow multiple users to select)
6. Customize the AlertDialog of the custom View (when the above method cannot meet your needs, you must customize it)
The sixth method is the implementation of custom content. For example, if you want to create a Login Dialog Box, the first five methods cannot be implemented.
At this time, the User-Defined logon interface is set through the setView of AlertDialog. Builder,
The titles and buttons are also Android-native. If you are using a custom method like this, please refer to the previous link to view the last method.
The second method is described here.
First, let's take a look at the effect. The left is the native AlertDialog, And the right is the custom AlertDialog. In this way, the user-defined interface is mainly used to make the interface more unified.
The Code is as follows:
String info = cityData. getPointerList (). get (position ). toString (); AlertDialog alertDialog = new AlertDialog. builder (CityActivity. this ). create (); alertDialog. show (); Window window = alertDialog. getWindow (); window. setContentView (R. layout. dialog_main_info); TextView TV _title = (TextView) window. findViewById (R. id. TV _dialog_title); TV _title.setText ("details"); TextView TV _message = (TextView) window. findViewById (R. id. TV _dialog_message); TV _message.setText (info );
Layout file:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffff" android:orientation="vertical" > <TextView android:id="@+id/tv_dialog_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#7a7" android:padding="8dp" android:textColor="#eee" android:textSize="20sp" android:textStyle="bold" /> <TextView android:id="@+id/tv_dialog_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:padding="3dp" /></LinearLayout>
In fact, the main purpose of customization here is to make the title background color green, consistent with the activity background green, more harmonious.
AlertDialog is a subclass of Dialog and can be customized based on Dialog. There are many methods, and try again.
Author: jason0539
Weibo: http://weibo.com/2553717707
Blog: http://blog.csdn.net/jason0539 (reprinted please explain the source)
Android custom AlertDialog Style
I only want to use style to inherit the system style-theme, but I cannot find the direction, such as the background of the system title and content background. In this example, I can use layout and view to implement it soon,
Android custom AlertDialog cannot remove the external Black edge
Yes.
It should be helpful in the future!