【问题标题】:White frame around my Alert Dialog Object?我的警报对话框对象周围有白框?
【发布时间】:2013-07-31 23:44:08
【问题描述】:

当我试图关闭按下的关闭按钮上的对话框时,问题就开始了。

我无法让它与我原来的方法一起工作,所以我尝试了这个,它在显示时对话框周围有一个奇怪的边框。

这是对话框类:

package com.Pivotl.PostcardsFromAlaska;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

public class PFADialogFragment extends DialogFragment {
    static PFADialogFragment newInstance() {
        PFADialogFragment f = new PFADialogFragment();
        return f;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        //getting proper access to LayoutInflater is the trick
        LayoutInflater inflater = getActivity().getLayoutInflater();

        View view = inflater.inflate(R.layout.enter_actions, null);
        //propManager = new PropManager(getSherlockActivity());
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(view);
        return builder.create();
    }

}

对话框视图:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="3dp" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:layout_marginRight="166dp"
        android:background="@layout/roundedshape"
        android:orientation="vertical"
        android:paddingBottom="10dp"
        android:paddingLeft="5dp"
        android:paddingRight="5dp" >

        <Button
            android:id="@+id/closeButton"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="135dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/close2x"
            android:onClick="closeButtonClick" />

        <Button
            android:id="@+id/takePictureButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@drawable/big_button2x"
            android:onClick="takePictureButtonClick" />

        <Button
            android:id="@+id/photoGalleryButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@drawable/big_button2x"
            android:onClick="photoGalleryButtonClick" />

        <Button
            android:id="@+id/artistGalleryButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@drawable/big_button2x"
            android:onClick="artistGalleryButtonClick" />

    </LinearLayout>

</RelativeLayout>

我使用 protected void onCreate(Bundle savedInstanceState) 访问并显示它 :

    if(!diagShowing)
   {
    showDialog();
   }

但是当它显示时如下所示:

为什么会显示这个边框,我怎样才能让它只显示我的视图?

任何帮助,不胜感激!

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    transparent background 添加到您的RelativeLayout,例如:

    android:background="@android:color/transparent"
    

    android:background="#00000000"
    

    或者您也可以为自定义对话框创建主题

    【讨论】:

    • 您是否在onCreatView 中尝试过getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));ColorDrawable 可以是:ColorDrawable(Color.TRANSPARENT)ColorDrawable(0)。这是同一件事。 stackoverflow.com/questions/8045556/…
    • 我也试过了,这实际上给了我一个空指针异常@Yann Masoch
    【解决方案2】:

    在onCreate中调用方法,如:

    @覆盖 public void onCreate(Bundle savedInstanceState) {

              super.onCreate(savedInstanceState);
              setStyle(STYLE_NO_FRAME,0);
    

    }

    【讨论】:

    • 我也试过了,但它仍然显示,我在我的 Dialog 类和主类中尝试过......两者仍然显示边框。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多