how to remove rectangle frame of the custom dialog

有些话、适合烂在心里 提交于 2020-02-02 03:43:10

问题


i custom a dialog :

public class CustomizeDialog extends Dialog implements OnClickListener {
Button close;
TextView tv;
public CustomizeDialog(Context context,String Stringcontent) {
    super(context);
    requestWindowFeature(Window.FEATURE_NO_TITLE);      
    setContentView(R.layout.custom_diolog_main);
    tv=(TextView) findViewById(R.id.content);
    tv.setText(Stringcontent);
    close = (Button) findViewById(R.id.close);
    close.setOnClickListener(this);
}

@Override
public void onClick(View v) {       
    if (v == close)
        dismiss();
}

 }

the xml is

   <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout  
   xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="100dip" 
android:orientation="vertical"
android:background="@drawable/custom_diolog_bg"
android:layout_width="250dip">
<TextView android:layout_height="wrap_content"
    android:textColor="#000" 
    android:textStyle="bold" 
    android:textSize="18sp"
    android:id="@+id/content"
    android:layout_marginLeft="15dip"
    android:layout_marginTop="5dip"
    android:layout_alignParentTop="true"
    android:layout_width="250dip" 
    android:text=" Custom Dialog "/>


<Button android:layout_width="70dip"  
    android:layout_marginLeft="80dip"
    android:background="@drawable/custom_dialog_button_bg"
    android:layout_alignParentBottom="true"
    android:layout_height="40dip" android:text="关闭"   
        android:id="@+id/close"></Button>
 </RelativeLayout>

my dialog is vrry well,but custom_diolog_bg is a rounded rectangle image,and when i show my dialog ,it show a system Frame behide my custom,so i used this.getwindow.setBackgroundDrawable(null),then the system Frame seems have remove but only the Four Corners not remove,we also see dark Four Corners,because i used the rounded rectangle image.so my question how to remove all the Frame so that my dialog seem Very well

the pic is http://i.stack.imgur.com/EG7oz.jpg ,so you can see there is dark frame in the last,how to remove it? thank you


回答1:


Solution that worked for me

<style name="DialogTheme" parent="@android:style/Theme.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>        
</style>

Dialog dialog = new Dialog(this, R.style.DialogTheme);



回答2:


Use following lines before calling setContentView() :-

getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawable(
            new ColorDrawable(android.graphics.Color.TRANSPARENT));

will work perfectly.




回答3:


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




回答4:


instead of calling

super(context);

call

super(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

Update : Use this xml layout instead

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="100dip"
    android:orientation="vertical"
    android:background="@drawable/custom_diolog_bg"
    android:layout_width="250dip">
    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:orientation="vertical"
        android:layout_centerInParent="true">
        <TextView
        android:layout_height="wrap_content"
        android:textColor="#000"
        android:textStyle="bold"
        android:textSize="18sp"
        android:id="@+id/content"
        android:layout_marginLeft="15dip"
        android:layout_marginTop="5dip"
        android:layout_alignParentTop="true"
        android:layout_width="250dip"
        android:text=" Custom Dialog " />
    <Button
        android:layout_width="70dip"
        android:layout_marginLeft="80dip"
        android:background="@drawable/custom_dialog_button_bg"
        android:layout_alignParentBottom="true"
        android:layout_height="40dip"
        android:text="关闭"
        android:id="@+id/close"></Button>
    </LinearLayout>
</RelativeLayout>



回答5:


Try this it worked for me like a charm.

ContextThemeWrapper wrapper = new ContextThemeWrapper(this, android.R.style.Theme_Holo);
final LayoutInflater inflater = (LayoutInflater) wrapper.getSystemService(LAYOUT_INFLATER_SERVICE);
AlertDialog.Builder builder = new AlertDialog.Builder(wrapper);


来源:https://stackoverflow.com/questions/7497449/how-to-remove-rectangle-frame-of-the-custom-dialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!