Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
787 views
in Technique[技术] by (71.8m points)

android - Remove alert dialog border With Custom Theme

enter image description here

In my application i am using alert dialog with rounded rectangle theme.But it have alertdialog rectangle and my theme.My problem is how to replace alert dialog border like dialog.I want to show this set item with own theme only.

I want output this manner instead of the above theme:

enter image description here

Main Activity:

AlertDialog.Builder alertSeverity = new AlertDialog.Builder(
           getActivity(), R.style.Theme_CustomDialog);
     alertSeverity.setTitle("Severity Status");
CharSequence[] severityStatus = { "Low-Severity",
           "Middle-Severity", "High-Severity" };
     alertSeverity.setItems(severityStatus,
           new DialogInterface.OnClickListener() {        

              @Override
              public void onClick(DialogInterface dialog, int which) {
                }
                 });

My Theme:

<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">
    <item name="android:windowBackground">@drawable/shapedialogtheme</item>
<item name="android:windowFrame">@null</item>

</style>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"  >

<solid android:color="#565656" />

<stroke
    android:width="5dp"
    android:color="#ffff8080" />

<corners android:radius="30dp" />

<padding
    android:bottom="10dp"
    android:left="10dp"
    android:right="10dp"
    android:top="10dp" />
<size 
    android:width="150dp"
    android:height="150dp"/>

</shape>

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use Dialog instead of AlertDialog.

Create your custom layout which you want to show in dialog and setContent in dialog. Apply this theme android.R.style.Theme_Translucent_NoTitleBar in dialog it will hide border.

Here is sample code.

Dialog dialog = new Dialog(activity.this, android.R.style.Theme_Translucent_NoTitleBar);

// your layout file
dialog.setContentView(R.layout.dialog);

// for hide title 
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

//for set title
dialog.setTitle("Custom Dialog");


dialog.show();

Updated:

just tried this in AlertDialog.

AlertDialog.Builder alertSeverity = new AlertDialog.Builder(
           getActivity(), android.R.style.Theme_Translucent_NoTitleBar);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...