Set Transparent Window in AlertDialog box

后端 未结 2 1299
刺人心
刺人心 2020-12-17 03:49

I want to set the Transparent window for the Default alertDialogbox. . . How can i able to do it ?? My Alertbox is as like this. Please refer it. .

Thanks in Advanc

相关标签:
2条回答
  • 2020-12-17 04:31

    The link is for activity How do I create a transparent Activity on Android?

    but still you can apply the same theme for dialog box too.

    Edit

    Create a class for the dialog as below

    CustDialog.java :

    public class CustomDialog extends Dialog implements android.view.View.OnClickListener {
    
        Button button_home,button_cancel,button_resume;
        public GamePauseMenu(Context context) {
            super(context,R.style.Theme_Transparent);
    
    
        }
        public void show(int bg) {
            // TODO Auto-generated method stub
            super.show();
            setContentView(R.layout.custdialog);
            button_resume = (Button)findViewById(R.id.imageButton1);
            button_resume.setOnClickListener(this);
        }
        public void onClick(View v) {
            cancel();
    
        }
    
    
    }
    

    custdialog.xml in Layout :

    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout android:id="@+id/linearLayout1"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:gravity="center|center_vertical|center_horizontal"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
        <Button android:id="@+id/imageButton1" android:background="@drawable/menu_home"
            android:layout_height="wrap_content" android:layout_width="fill_parent"
            android:drawingCacheQuality="auto" android:duplicateParentState="true"></Button>
        <Button android:background="@drawable/menu_next" android:id="@+id/imageButton2"
            android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>
        <Button android:id="@+id/imageButton3" android:background="@drawable/menu_reset"
            android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>
    
    </LinearLayout>
    
    0 讨论(0)
  • 2020-12-17 04:38

    Hey... Now i m able to do it. . . The code is as Follow. . .

    <style name="Theme.Transparent" parent="@android:style/Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:alertDialogStyle">@style/MyOwnAlertbox</item></style>
    
    
    
    <style name="MyOwnAlertbox" parent="@android:style/AlertDialog">
     <item name="android:fullDark">@color/light_blue</item>
     <item name="android:topDark">@color/black</item>
     <item name="android:centerDark">@color/red</item>
     <item name="android:bottomDark">@color/green</item>
     <item name="android:fullBright">@color/white</item>
        <item name="android:topBright">@color/black</item>
        <item name="android:centerBright">@color/white</item>
    
        <item name="android:bottomMedium">@color/red</item>
        <item name="android:centerMedium">@color/blue</item>
    

    Just add that Style in Your Manifest file. .. as like. . . android:theme="@style/Theme.Transparent"

    Have Fun. . .

    0 讨论(0)
提交回复
热议问题