Android底部导航栏自定义

标签 android material-design bottomnavigationview android-bottomnav bottombar

我已经成功实现了简单的底部栏,它看起来像图 1。但我想进一步自定义它,使其看起来像 Youtube 的 android 应用程序中的底部栏,当你点击其中一个项目时,它会展开阴影效果。

我当前的底栏:

My current bottom bar

Youtube 的底栏

Youtube's bottom bar

我还想将其自定义为看起来像官方站点中的那个,在单击项目时带有一些动画。

Other bottom bar style

任何 fragment 或教程链接将不胜感激。谢谢

最佳答案

试试这个

使用 Android 波纹效果自定义颜色:

在drawable文件夹中创建button.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/colorPrimaryDark"/>
<item android:drawable="@color/colorPrimary"/>
</selector>

在 drawable-v21 文件夹中创建 button.xml

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
<item android:drawable="@color/colorPrimary" /> 
</ripple>

应用在你的主题中

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlHighlight">@color/colorPrimaryDark</item>
</style>

现在您可以将 button.xml 设置为 View 的背景。

 android:background="@drawable/button"

如有任何疑问follow this link

关于Android底部导航栏自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44083507/

相关文章:

android - 工具栏仅在平板电脑尺寸上具有左右填充

java - 使用自定义图标时增加导航底部 View android中选定图标的高度?

android - 什么是 Android 项目中的 .project 文件?

java - 调用请求限制

java - 需要澄清 Android 和应用程序架构中的 XML 文件

android - 如何在 Jetpack Compose Material 3 中制作 cradled FAB?

android - 如何在 Android 应用程序中添加额外的菜单项?

javascript - Material Design Lite 插件正则表达式 javascript

android - BottomNavigationView:更改标题和图标之间的间隙大小

android - 使用导航组件和导航图在 Fragment(非 Activity )内使用 BottomNavigationView 导航