如何去掉自定义对话框的矩形框

发布于 2024-12-05 19:48:55 字数 1913 浏览 0 评论 0原文

我自定义一个对话框:

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();
}

 }

xml是

   <?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>

我的对话框,很好,但是custom_diolog_bg是一个圆角矩形图像,当我显示我的对话框时,它显示一个隐藏在我的自定义后面的系统框架,所以我使用了this.getwindow.setBackgroundDrawable(null),那么系统框架似乎已删除,但只有四个角没有删除,我们还看到黑暗的四个角,因为我使用了圆角矩形图像。所以我的问题如何删除所有框架,以便我的对话框看起来很好,

图片是 https://i.sstatic.net/EG7oz.jpg ,所以你可以看到最后有黑框,如何去除它?谢谢

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 https://i.sstatic.net/EG7oz.jpg ,so you can see there is dark frame in the last,how to remove it? thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

思念绕指尖 2024-12-12 19:48:55

对我有用的解决方案

<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);

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);
你另情深 2024-12-12 19:48:55

在调用 setContentView() 之前使用以下几行:-

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

将完美工作。

Use following lines before calling setContentView() :-

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

will work perfectly.

空城旧梦 2024-12-12 19:48:55

对话框 mydialog = 新对话框(this,android.R.style.Theme_Translucent_NoTitleBar);

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

度的依靠╰つ 2024-12-12 19:48:55

而不是调用

super(context);

调用

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

更新: 使用此 xml 布局代替

<?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>

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>
我要还你自由 2024-12-12 19:48:55

试试这个,它对我来说就像一个魅力。

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文