【问题标题】:Create a full screen RelativeLayout programmatically以编程方式创建全屏 RelativeLayout
【发布时间】:2017-04-17 07:03:11
【问题描述】:

我需要像对话框的灰色背景一样以编程方式创建全屏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));

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

【问题讨论】:

  • 你想使用这个对话框的布局背景吗?我不明白你的需求是什么?
  • 要隐藏操作栏你可以试试getSupportActionBar().hide();
  • 编辑您的问题...使用任何图片...或您的问题的详细信息以及您当前的代码有什么问题...?

标签: android android-layout views android-relativelayout programmatically


【解决方案1】:

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

 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    • 2014-10-14
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    相关资源
    最近更新 更多