Android:如何显示父活动及其按钮/导航视图的片段

问题描述 投票:0回答:1

我有一个主要活动,该活动通过片段事务启动片段。我希望该片段completely填充屏幕,根本不显示父视图。但是,当我提交片段事务时,我仍然可以看到父活动的底部导航视图及其按钮。我做了一个小样的演示应用程序来显示我的意思:

主要活动的背景为黄色。 “ Testclick”按钮使用下面的代码启动片段事务。

enter image description here

这是交易的结果。片段的红色背景现在可见,但是bottomNavigationView和Buttons仍然可见(不需要)。

enter image description here

片段交易

bttn.setOnClickListener {
            supportFragmentManager
                .beginTransaction()
                .replace(R.id.contentview, Frag1())
                .addToBackStack(null)
                .commit()
        }

主要活动布局

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/contentview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/yellow"
    tools:context=".MainActivity">

...

</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

enter image description here

android android-fragments android-view bottomnavigationview
1个回答
1
投票

您的R.id.contentview必须在按钮后面的背景中

啊,您实际上知道有什么很好的工具,在工具->布局检查器中称为LayoutInspector,您实际上可以查看活动运行时如何设置布局。您的情况是将片段的布局添加到活动的布局内。

抱歉,起初没有看到ID

© www.soinside.com 2019 - 2024. All rights reserved.