DialogFragment:隐藏父活动视图

时间:2018-09-24 21:01:42

标签: android android-dialogfragment

我使用以下代码在我的应用中显示了全屏对话框:

public class VideoOfDayFragment extends DialogFragment {

private static final String TAG = VideoOfDayFragment.class.getSimpleName();

private Toolbar toolbar;
private TextView actionTV;
private VideoView videoView;

private MediaController controller;
private Uri vidUri;
private String videoUrl;

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

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

    initViews(v);
    toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.action_close));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            skipVOD();
        }
    });
    toolbar.setTitle("Video of Day");

    return v;
}

@Override
public void onStart() {
    super.onStart();
    Dialog dialog = getDialog();
    if (dialog != null) {
        int w = ViewGroup.LayoutParams.MATCH_PARENT;
        int h = ViewGroup.LayoutParams.MATCH_PARENT;
        dialog.getWindow().setLayout(w, h);
    }
}

private void skipVOD() {
    startActivity(new Intent(getActivity(), HomeActivity.class));
    getActivity().finish();
}

private void initViews(View v) {
    toolbar = v.findViewById(R.id.toolbar);
    actionTV = v.findViewById(R.id.actionTV);
    videoView = v.findViewById(R.id.videoView);
}
}

这是对话框样式:

<style name="DialogFullScreen" parent="Theme.AppCompat.Dialog">
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowBackground">@android:color/black</item>
</style>

在主机活动适配器中,我调用了show方法:

VideoOfDayFragment dayFragment = new VideoOfDayFragment();
                    FragmentTransaction ft = ((AppCompatActivity)context).getFragmentManager().beginTransaction();
                    dayFragment.show(ft, dayFragment.getTag());

除了没有显示的工具栏标题外,它都可以正常工作,但主要的问题是主机活动ui元素仍然可见。如何使该对话框视图独立?

0 个答案:

没有答案