【问题标题】:bottom bar layout with selected box?带有选定框的底栏布局?
【发布时间】:2018-02-24 06:10:22
【问题描述】:

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

我开发了这个东西

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

这是我需要的

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

这是我的代码

    <?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代码

标签: android android-layout android-xml android-menu bottomnavigationview


【解决方案1】:

只需将 selector drawable 添加到 xml 中的 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>

Inxml.

<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>

根据需要修改选择器。并制作多个选择器。在 drawable 中低于 API21 的 Normal 。以上 API21 的 drawable-v21。

【讨论】:

  • 我试过了。但是图标是隐藏的,点击项目后只显示背景颜色。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多