2016-08-11 69 views
2

我创建它使用对话框fragement它看起来像这样默认情况下在DialogFragment中获取边距?

enter image description here

正如你可以看到我得到一个顶边距其中didnt设置对话框片段上的应用程序,你可以从我的XML文件

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

<TextView 
    android:id="@+id/tv_title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/str_add_drop" 
    android:textSize="@dimen/tv_title_font_size"/> 
<ImageButton 
    android:background="@null" 
    android:id="@+id/btn_close" 
    android:layout_width="12dp" 
    android:layout_height="12dp" 
    android:src="@drawable/ic_close" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@id/tv_title" 
    android:layout_alignBottom="@id/tv_title" 
    android:layout_marginRight="5dp" 
    /> 
<EditText 
    android:id="@+id/et_drop" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/tv_title" 
    android:hint="@string/hint_et_drop" 
    android:padding="16dp" 
    android:inputType="textVisiblePassword"/> 

<DatePicker 
    android:id="@+id/bpv_date" 
    android:layout_width="match_parent" 
    android:layout_height="300dp" 
    android:layout_below="@id/et_drop"></DatePicker> 
<Button 
    android:id="@+id/btn_add_it" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/bpv_date" 
    android:text="@string/str_add_it" 
    android:textAllCaps="false"/> 

</RelativeLayout> 

请告诉我为什么我得到这个保证金默认情况下,我该如何纠正这一点。

回答

1

请尝试:

getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

但之前的onCreate(的setContentView方法您的自定义对话框)方法。

+0

什么是'getWindow()'我的计划没有按不认识它 –

+0

从哪里访问对话..?片段或活动..?尝试这些:getActivity()。getWindow()....或getDialog()。getWindow().....或最后dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); – Pkosta

+0

我从Fragment子类访问。我想我不能在片段上下文中使用'getWindow()' –

0

您可以参考这个Link我希望帮助你

0

没有必要在你的对话框XML文件中的任何改变,只为您的对话片段的风格。下面 的代码将覆盖无边框整个活动:

RES /价值/ styles.xml

<resources> 
    ... 
    <!-- your dialog style --> 
    <style name="DialogFragment" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <item name="android:windowBackground">@color/white</item> 
     <item name="android:windowNoTitle">true</item> 
     <item name="android:windowIsFloating">true</item> 
     <item name="android:layout_gravity">center</item> 
     <item name="android:windowCloseOnTouchOutside">true</item> 
    </style> 
</resources> 

YourDialogFragment.java

public class YourDialogFragment extends DialogFragment implements View.OnClickListener 
{ 
    private Dialog mDialog; 

    @NonNull 
    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) 
    { 
     mDialog = new Dialog(getActivity(), R.style.DialogFragment); 

     WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); 
     layoutParams.copyFrom(mDialog.getWindow().getAttributes()); 
     layoutParams.windowAnimations = R.style.SlideUpDownDialog; 

     final View view = View.inflate(getActivity(), R.layout.dialog_fragment_layout, null); 
     mDialog.getWindow().setAttributes(layoutParams); 
     mDialog.setContentView(view); 

     return mDialog; 
    } 


    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    { 
     View v = inflater.inflate(R.layout.dialog_fragment_layout, container, false); 

     mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 

     return v; 
    } 

    ... 
}