首页 > 解决方案 > 将显示和隐藏按钮添加到 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 中添加一个带有“显示”和“隐藏”按钮的栏。当我点击显示它会显示ListView,当它隐藏它会隐藏这个ListView。我可以做吗?

标签: androidandroid-layoutlistviewandroid-design-library

解决方案


答案中已经给出了显示和隐藏功能,所以我将添加“带有显示和隐藏按钮的栏”的示例

<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 功能。


推荐阅读