[Android interface] How to get rid of dialog black background and border DEMO

Source: Internet
Author: User

The default dialog for Android is a black background, white border style, which is pretty good for Android, but it doesn't match your project style, so you have to try to rewrite his style, of course dialog is supported by style rewriting.

Use new Dialog (context, style). Setcontentview (layout);

You can customize the dialog of your project

Of course, the style here plays a vital role, knowing that the white side that doesn't match the project depends on it.

Create a new Style.xml under value

Share My code below:

First: mainactivity

12345678910111213141516171819202122232425 protected void onCreate(Bundle savedInstanceState) {    // TODO Auto-generated method stub    super.onCreate(savedInstanceState);    setContentView(R.layout.main);}      public void dialogStyle(View v){      final Dialog d=new Dialog(this, R.style.dialog);       View vv = LayoutInflater.from(this).inflate(R.layout.dialog_test, null);       TextView delete = (TextView) vv.findViewById(R.id.delete);              d.setCanceledOnTouchOutside(true);       d.setContentView(vv);       d.show();              delete.setOnClickListener(new OnClickListener() {                @Override        public void onClick(View arg0) {            // TODO Auto-generated method stub            d.dismiss();        }    });   }}

Then: Style

123456789    <style name="dialog" parent="@android:style/Theme.Dialog"<item name="android:windowFrame">@null</item>  <item name="android:windowIsFloating">true</item>  <item name="android:windowIsTranslucent">false</item>  <item name="android:windowNoTitle">true</item>  <item name="android:background">@null</item>  <item name="android:backgroundDimEnabled">false</item>  <item name="android:windowBackground"> @android:color/transparent </item></style>

Last XML

123456789 <!--?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:orientation="vertical">             <relativelayout android:layout_width="fill_parent" android:layout_height="wrap_content">        <textview android:id="@+id/delete" android:layout_width="238dp" android:layout_height="58dp" android:background="#2c2c2c" android:text="删除联系人" android:textcolor="#ffffff" android:gravity="center" android:layout_centerhorizontal="true"></textview></relativelayout></linearlayout>

[Android interface] How to get rid of dialog black background and border DEMO

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.