Android custom dialog background transparent and display position settings

Source: Internet
Author: User

Paste the display first, for reference only:

The code is as follows:

1. Custom Dialog

 Public class Selectdialog extends alertdialog{publicint  theme) {    super (context, theme);}  Public Selectdialog (Context context) {    super (context);} @Overrideprotectedvoid  onCreate (Bundle savedinstancestate) {    super.oncreate ( Savedinstancestate);    Setcontentview (R.layout.slt_cnt_type);}}

2. layout file Slt_cnt_type.xml code

<?xml version="1.0"encoding="Utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="Vertical"android:padding="10DP"Android:layout_width="115DP"android:layout_height="wrap_content"Android:background="@color/blue"> <button android:layout_height="wrap_content"Android:background="#00000000"Android:layout_width="fill_parent"android:text="All Contact person"android:paddingtop="5DP"Android:paddingbottom="5DP"android:paddingleft="10DP"android:gravity="left|center_vertical"Android:id="@+id/btnsltcntall"></Button> <button android:layout_height="wrap_content"Android:background="#00000000"style="@drawable/greenhand_button"android:text="Plump Users"android:gravity="left|center_vertical"Android:paddingbottom="5DP"android:paddingtop="5DP"android:paddingleft="10DP"android:paddingright="10DP"Android:layout_width="fill_parent"Android:id="@+id/btnsltgudonguser"></Button> <button style="@drawable/greenhand_button"Android:background="#00000000"android:layout_height="wrap_content"Android:layout_width="fill_parent"android:text="Recommended Users"android:gravity="left|center_vertical"android:paddingtop="5DP"Android:paddingbottom="5DP"android:paddingleft="10DP"Android:id="@+id/btnsltrecommend"></Button></LinearLayout>

3. Color Color.xml Code

<?xml version="1.0" encoding="utf-8"? ><resources >  <color name="transparent">#00000000</color></ Resources>

4. Style Style.xml Code

<?xml version="1.0"encoding="Utf-8"?><resources> <style name="Dialog"Parent="@android: Style/theme.dialog"> <item name="Android:windowframe"> @null </item><!--border-<item name="android:windowisfloating">true</item>< whether!--is on the activity--<item name="android:windowistranslucent">false</item><!--Translucent--<item name="Android:windownotitle">true</item><!--Untitled-<item Name="Android:windowbackground"> @color/transparent</item><!--Background Transparent--<item name="android:backgrounddimenabled">false</item><!--Blur--</style></resources>

4. Display dialog

Selectdialog Selectdialog =NewSelectdialog ( This, R.style.dialog);//Create dialog and set style themesWindow win =Selectdialog.getwindow (); Layoutparamsparams=Newlayoutparams ();params. x =- the;//set X coordinateparams. y =- -;//Set Y coordinateWin.setattributes (params); Selectdialog.setcanceledontouchoutside (true);//Set Click Dialog outside any area to close dialogSelectdialog.show ();

Above only for reference, if there is a problem, please put forward in time, Exchange learning!

Android custom dialog background transparent and display position settings

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.