Android DialogFragment如何删除1px边框

时间:2014-09-13 08:53:02

标签: android android-layout android-alertdialog

我有一个DialogFragment,在对话框周围显示一个小的黑色边框(看起来像1 px宽度)。我希望我的对话框是扁平的,没有边框也没有渐变。我该如何删除?

我尝试使用以下代码但没有成功:

public Dialog onCreateDialog(Bundle savedInstanceState) {

  ...

  AlertDialog result = builder.create();
  result.setView(rootView, 0, 0, 0, 0);
  result.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
  return result;
  //return builder.create();
  }

enter image description here

1 个答案:

答案 0 :(得分:1)

试试这段代码

public class QuickActionFragment extends DialogFragment {

  @Override
 public Dialog onCreateDialog(Bundle savedInstanceState) {
       Dialog m_dialog = new Dialog(QuickActionFragment.this, R.style.Dialog_No_Border);
      LayoutInflater m_inflater = LayoutInflater.from(CustomDialogActivity.this);
      View v = LayoutInflater.from(mContext).inflate(R.layout.view_quick_action, null, false);
        // SET ALL THE VIEWS
        m_dialog.setTitle(null);
    m_dialog.setContentView(m_view);
    m_dialog.show();
        return dialog;
 }
}

在res / value / style.xml文件中添加Dialog_No_Border样式。

<style name="Dialog_No_Border">
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowBackground">@color/transparent_color</item>
</style>

清理项目,然后运行