1

我打开对话框片段。但是,它不占用整个屏幕。我的意思是它留下了一些空间。不占用完整屏幕的对话框片段

下面是我的代码:

public class MyDialogFragment extends DialogFragment implements View.OnClickListener{ 
     private Context context = getActivity(); 

     private ImageView imageViewCancel; 
     private TextView textViewTitle; 
     private View view; 

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

      getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

      textViewTitle = (TextView) view.findViewById(R.id.textView_Screen_Title); 
      setHeader("Some title"); 
      imageViewCancel = (ImageView) view.findViewById(R.id.imageView_Cancel); 
      imageViewCancel.setOnClickListener(this); 


      //to hide keyboard when showing dialog fragment 
      getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

      return view; 
     } 

     private void setHeader(String screenTitle) { 
      textViewTitle.setText(screenTitle); 
     } 

     @Override 
     public void onClick(View view) { 
      switch (view.getId()) { 
       case R.id.imageView_Cancel : 
        dismiss(); 
        break; 
      } 
     } 

     @Override 
     public void onStart() { 
      super.onStart(); 
getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); 
     } 
    } 

参考快照

enter image description here

我想在全屏模式下打开它,这样的背景透明不会被看到。试过WindowManager.LayoutParams.MATCH_PARENT & ViewGroup.LayoutParams.MATCH_PARENT太,但没有什么作品。

+0

检查此[链接](http://stackoverflow.com/questions/18315343/android-make-a-dialog-appear-in-fullscreen) –

回答

1

创建Dialog

<style name="CustomDialog" parent="AppTheme" > 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:windowCloseOnTouchOutside">true</item> 
</style> 

自定义样式,然后使用该样式对话框片段

@Override public void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog); 
} 

@Override public void onStart() { 
    super.onStart(); 
    getDialog().getWindow() 
    .setLayout(WindowManager.LayoutParams.MATCH_PARENT, 
     WindowManager.LayoutParams.MATCH_PARENT); 
} 

SampleDialogFragment sampleDialogFragment = new SampleDialogFragment(); 
SampleDialogFragment.show(getActivity().getSupportFragmentManager(), "sometag"); 
+0

日Thnx .....部分为我工作 – VVB

+0

让我知道你有它的问题 – arjun

+0

保持或部分只...上面1没有在其他设备上工作 – VVB

0

试试这个: 在styles.xml

<style name="MY.DIALOG" parent="android:Theme" > 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowIsFloating">false</item> 
</style> 

并设置添加此这种风格在你的DialogFragment中:

@Override 
public void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setStyle(DialogFragment.STYLE_NORMAL, R.style.MY_DIALOG); 
} 

对话框片段的背景将显示为黑色,根据需要进行更改。

请参阅这篇文章的详细信息: http://www.techrepublic.com/article/pro-tip-unravel-the-mystery-of-androids-full-screen-dialog-fragments/