小编Ben*_*ihr的帖子

我如何在NavHostFragment中检索当前片段?

我试图在新的导航组件中找到一个方法,但我没有找到任何相关的方法.

我目前的目的地是:

mainHostFragment.findNavController().currentDestination
Run Code Online (Sandbox Code Playgroud)

但我无法获得任何对显示片段的引用.

android android-fragments kotlin android-architecture-components android-architecture-navigation

10
推荐指数
6
解决办法
7282
查看次数

在 ConstraintLayout 中以编程方式添加视图

我尝试在 ConstraintLayout 中另一个视图的同一位置添加一个视图,但添加的视图没有获得另一个视图的 LayoutParams。

添加的视图发生在容器的左上角|。

这是我的代码:

TextView cloneView = new TextView(getContext());
cloneView.setLayoutParams(otherView.getLayoutParams());
mainContainer.addView(cloneView);
Run Code Online (Sandbox Code Playgroud)

android android-constraintlayout

8
推荐指数
1
解决办法
1万
查看次数

如何以编程方式显示/隐藏AppBottomBar?

我尝试使用AppBottomBar,并且希望能够像setExpanded在AppBarLayout中一样以编程方式隐藏或显示它。

我的布局就像

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
          ...
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:id="@+id/nested"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <fragment
            android:id="@+id/navHost"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:navGraph="@navigation/home_nav" />
    </androidx.core.widget.NestedScrollView>

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        style="@style/Widget.MaterialComponents.BottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:backgroundTint="@color/colorPrimary"
        app:fabAlignmentMode="center"
        app:hideOnScroll="true"
        app:layout_scrollFlags="scroll|enterAlways"
        app:navigationIcon="@drawable/ic_menu"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我尝试使用AppBottomBar的行为,但是不起作用。

android kotlin material-design android-bottomappbar

5
推荐指数
2
解决办法
480
查看次数