0

我需要像对话框的灰色背景一样以编程方式创建全屏RelativeLayout(它位于每个视图的顶部)。

我试试这个,但 ActionBar 在上面:

rlContainerLayout = new RelativeLayout(activity);
rlContainerLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT , RelativeLayout.LayoutParams.MATCH_PARENT ));
rlContainerLayout.setBackgroundColor(ContextCompat.getColor(activity,R.color.color_gray));
activity.addContentView(rlContainerLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

那么我怎样才能实现对话框背景之类的东西呢?

4

1 回答 1

2

在创建布局之前试试这个。

 setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }

    create and add your Views here
于 2017-04-17T07:18:57.863 回答