Remove alert dialog border With Custom Theme

2019-01-24 20:39发布

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

6条回答
别忘想泡老子
2楼-- · 2019-01-24 20:59

You can not remove border from alert dialog.

use this

public class ActivityIndicator extends Dialog implements android.view.View.OnClickListener{
protected static final String TAG = InfoIndicator.class.getName();
ImageView close;
WebView info;

      public ActivityIndicator (Context context,String information) 
       {
          super(context, android.R.style.Theme_Translucent_NoTitleBar);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.info);
          setCancelable(true);
           }
}

and try this below function for show, hide and clear dialog

private static ActivityIndicator activityIndicator;

public static void hideActivityViewer() {
    if (activityIndicator != null) {
        activityIndicator.dismiss();
    }
    activityIndicator = null;
}

public static void showActivityViewer(Context context) {
    if (activityIndicator == null)
    {
        activityIndicator = new ActivityIndicator(context);
    }
    activityIndicator.show();

}
public static void clearDialogs()
{
    activityIndicator = null;
}
查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-24 21:13

You need to design a custom dialog for this purpose :

**dialog.xml**

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/txt_view_SaveAs"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/save_as"
    android:layout_margin="10dp"
    android:textSize="25dp" />

<EditText
    android:id="@+id/edit_txt_SaveAs"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="300dp"
    android:maxLines="1"
    android:textSize="20dp"
    android:maxLength="50"
    android:layout_margin="10dp"
    android:text="@string/save_as" />

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_margin="10dp"
    android:weightSum="1.0" >

    <Button
        android:id="@+id/btn_SaveAs"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight="0.5"
        android:minWidth="100dp"
        android:textSize="20dp"
        android:text="@string/save"
        android:layout_margin="3dp" />

    <Button
        android:id="@+id/btn_Cancel"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight="0.5"
        android:minWidth="100dp"
        android:textSize="20dp"
        android:text="@string/cancel"
        android:layout_margin="3dp" />

</LinearLayout>

You can then make different class for the particular dialog like this:

public class SaveDialog extends Dialog implements android.view.View.OnClickListener {

private Context context;

private TextView txt_view_SaveAs;
private EditText edit_txt_SaveAs;
private Button btn_SaveAs;
private Button btn_Cancel;

public SaveDialog(Context context) {
    super(context);
    this.context = context;
    // TODO Auto-generated constructor stub
}

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dialog);

    setCancelable(true); // Setting the Dialog to be Cancellable on Back Key Press

    txt_view_SaveAs = (TextView) findViewById(R.id.txt_view_SaveAs);
    edit_txt_SaveAs = (EditText) findViewById(R.id.edit_txt_SaveAs);
    btn_SaveAs = (Button) findViewById(R.id.btn_SaveAs);
    btn_SaveAs.setOnClickListener(this);
    btn_Cancel = (Button) findViewById(R.id.btn_Cancel);
    btn_Cancel.setOnClickListener(this);
}

@Override
public void onClick(View v) {
        // Write code for all the buttons on click methods
}
}

Then you can call the custom dialog in your main class by using the following code :

SaveDialog save_dialog = new SaveDialog(saving_activity);
save_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
save_dialog.show();
查看更多
Lonely孤独者°
4楼-- · 2019-01-24 21:15

Use Dialog instead of AlertDialog

Dialog callAlert = new Dialog(LoginActivity.this,R.style.CutomDialog);  
callAlert.setContentView(R.layout.call);

Style.xml

<style name="CutomDialog" parent="android:style/Theme.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowAnimationStyle">@style/Animations.DialogAnimation</item>
</style>

call.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp"
 android:background="@drawable/call_bg"></RelativeLayout>

call_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="3dp" android:color="#A20B3F" />

<corners android:bottomRightRadius="4dp" android:bottomLeftRadius="4dp" 
 android:topLeftRadius="4dp" android:topRightRadius="4dp"/> 

Main thing is that you have to make layout backgrpund transparent otherwise you will not able to get output as you want.

查看更多
Emotional °昔
5楼-- · 2019-01-24 21:15

you can use popwindow for more style by yourself

查看更多
聊天终结者
6楼-- · 2019-01-24 21:20

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);
查看更多
Bombasti
7楼-- · 2019-01-24 21:20

try the next solution:

extend from dialog, and set the exact view to use by using setContentView .

the alertDialog is used for some functionalities. it's not that it can do anything you want.

maybe instead of extending you could take the dialog and then use the setContentView.

查看更多
登录 后发表回答