将显示和隐藏按钮添加到 BottomNavigationView

Adding Show and Hide button to BottomNavigationView

我有这个代码;

<android.support.design.internal.BottomNavigationItemView
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <ListView
        android:id="@+id/list_time"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#E0E0E0"
        android:dividerHeight="4px" />

</android.support.design.internal.BottomNavigationItemView>

我想向此 ItemView 添加一个带有 "Show" 和 "Hide" 按钮的栏。当我单击显示时,它将显示 ListView,当我单击隐藏时,它将隐藏此 ListView。我可以吗?

您可以使用这些方法来显示和隐藏

    v.setVisibility(View.INVISIBLE);
    v.setVisibility(View.VISIBLE);

或者如果您想隐藏和使用其他布局组件的位置,您可以使用:

v.setVisibility(View.GONE);

答案中已经给出了显示和隐藏功能,因此我将添加 "bar with a Show and Hide button"

的示例
<android.support.design.internal.BottomNavigationItemView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2"
        android:background="#123123">

        <Button
            android:id="@+id/btn_show"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Show" />

        <Button
            android:id="@+id/btn_hide"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Hide" />
    </LinearLayout>


    <ListView
        android:id="@+id/list_time"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#E0E0E0"
        android:dividerHeight="4px" />

</android.support.design.internal.BottomNavigationItemView>

然后使用其他答案应用按钮的 onclick 功能。