Original Android Custom Alertdialog Ultimate Solution (pro-Test effective!) )

Source: Internet
Author: User

problem: Custom Alertdialog appear black Edge To run a code snippet:
View view = View.inflate(context, R.layout.dialog_common, null);mDialog = new AlertDialog.Builder(context).create();mDialog.setView(view);mDialog.show();

Dialog_common.xml
<?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=" Wrap_ Content "    android:background=" @drawable/shape_dialog_white "    android:o rientation= "Vertical" >    <LinearLayout        android: Layout_width= "Match_parent"         android:layout_height= "Wrap_content"         android:layout_marginbottom= "35DP"          android:layout_margintop= "35DP"         android:gravity= "center" >        <TextView             android:id= "@+id/dialog_tv_content"              Android:layOut_width= "Wrap_content"             android:layout_ height= "Wrap_content"             android:text= "@string/ Dialog_edit_wall_title "            android:textcolor=" @ Android:color/black "            android:textsize=" 19SP "/ >    </LinearLayout>    <View         android:layout_width= "match_parent"         android:layout_height= "1DP"         android:background= "@color/app_color"/>    < linearlayout        android:layout_width= "Match_parent"          android:layout_height= "Wrap_content"         android: Gravity= "CenteR ">        <TextView             android:id= "@+id/dialog_tv_left"              android:layout_width= "Wrap_content"             android:layout_height= "Wrap_content"             android: Layout_marginbottom= "12DP"             android:layout_ margintop= "12DP"             android:layout_weight= "1"             android:gravity= "center"              android:text= "@string/dialog_edit_wall_secede"              android:textcolor= "@android: Color/black"/>         <TextView            android:id= "@+id /dialog_tv_right "            android:layout_width=" Wrap_ Content "            android:layout_height=" Wrap_content "             android:layout_marginbottom= "12DP"              android:layout_margintop= "12DP"              android:layout_weight= "1"              android:gravity= "center"              android:text= "@string/dialog_new_reply_cancel"              android:textcolor= "@color/app_color"/>    </linearlayout></ Linearlayout>

Run-time (there is a circle of black edges!) ):

solve the problem: 1. Baidu Search "Android custom Alertdialog Remove Black edge", to conclude 3 words: "Then egg"! Most of them do this:     Modify code:
mDialog.setView(view);
is:
mDialog.setView(view,0,0,0,0);

run time (what is called "but the egg", the thick black edge becomes the thin black edge, the result black edge is still in):


2. Analysis: The layout of your own writing is not a problem, obviously alertdialog style or theme problem. 3. Ultimate Solution:     Add a style
    <!--styles.xml on API 14+ devices-->    <style name= "Sampletheme.light" parent= " Android:Theme.Holo.Light.DarkActionBar ">        <item name=" Android: Windownotitle ">true</item>    </style>

     add to Layout or androidmanifest.xml (I was added to Androidmanifest.xml, layout can be added to see for yourself ) )
   <activity android:name="com.kesar.ui.MainActivity"              android:theme="@style/SampleTheme.Light"/>

runtime (Next is the time to witness miracles!) ):



List of attachments
    • 1.png
    • 2.png
    • 3.png

Original Android Custom Alertdialog Ultimate Solution (pro-Test effective!) )

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.