Remove alert dialog border With Custom Theme

后端 未结 6 1558
广开言路
广开言路 2020-12-17 05:40

\"enter

In my application i am using alert dialog with rounded rectangle theme.But it

相关标签:
6条回答
  • 2020-12-17 06:18

    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;
    }
    
    0 讨论(0)
  • 2020-12-17 06:22

    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();
    
    0 讨论(0)
  • 2020-12-17 06:33

    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.

    0 讨论(0)
  • 2020-12-17 06:39

    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.

    0 讨论(0)
  • 2020-12-17 06:39

    you can use popwindow for more style by yourself

    0 讨论(0)
  • 2020-12-17 06:41

    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);
    
    0 讨论(0)
提交回复
热议问题