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

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

我有这个代码;

<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。我可以做吗?

android android-layout listview android-design-library
3个回答
0
投票

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

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


0
投票

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

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

0
投票

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

v.setVisibility(View.GONE);
© www.soinside.com 2019 - 2024. All rights reserved.