繁体   English   中英

带有选定框的底部栏布局?

[英]bottom bar layout with selected box?

我正在开发一个 android 应用程序。

我开发了这个东西

在此处输入图片说明

但是我需要像这样在选定的菜单项后面开发一个框。

这个我需要

在此处输入图片说明

我希望你帮助我开发这个。

这是我的代码

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="project.andromeeda.testproject.MainActivity">
<FrameLayout
    android:id="@+id/replace"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</FrameLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="#ddd"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation"
        app:itemBackground="@drawable/list"
        app:itemTextColor="@color/grey"/>

</android.support.constraint.ConstraintLayout>

现在它只显示没有文本或图标的背景颜色。

只需在 xml 中将selector drawable 添加到app:itemBackground

下面是一个例子。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/red" android:state_checked="true"/>
<item android:drawable="@color/gray"/>
</selector>

输入法。

<android.support.design.widget.BottomNavigationView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:itemBackground="@drawable/item_selector"
    ></android.support.design.widget.BottomNavigationView>

根据您的需要修改选择器。 并制作多个选择器。 a Normal for below API21 inside drawable 。 上面 API21 的 drawable-v21。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM