简体   繁体   English

在底部导航栏图标周围创建一个椭圆形 - Android

[英]Create an oval shape around Bottom Navigation Bar Icon - Android

I am trying to create an oval shape around my bottom navigation icon when selected as seen in the screenshot当在屏幕截图中选择时,我正在尝试在底部导航图标周围创建椭圆形形状

bottom_nav_layout.xml bottom_nav_layout.xml

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottomNav_view"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:elevation="0dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:theme="@style/Widget.BottomNavigationView"
    app:itemIconSize="20dp"
    app:itemIconTint="@color/bottom_nav_color"
    app:itemTextColor="@color/bottom_nav_color"
    app:labelVisibilityMode="labeled"
    app:layout_constraintBottom_toBottomOf="parent"
    app:menu="@menu/bottom_nav_menu" />

bottom_nav_color.xml bottom_nav_color.xml

  <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_checked="true" android:color="#3375BB" />
  <item android:state_checked="false" android:color="#68788D"/>
 </selector>

bottom_nav_menu.xml bottom_nav_menu.xml

  <?xml version="1.0" encoding="utf-8"?>
  <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
     android:id="@+id/navigation_home"
     android:icon="@drawable/ic_trustwallet"
     android:title="Wallet" />
   <item
    android:id="@+id/navigation_discover"
    android:icon="@drawable/ic_discover"
    android:title="Discover" />
  <item
    android:id="@+id/navigation_browser"
    android:icon="@drawable/ic_browser"
    android:title="Browser" />
  <item
    android:id="@+id/navigation_settings"
    android:icon="@drawable/ic_paper_settings"
    android:title="Settings" />


  </menu>

Use a M3 theme in your app:在您的应用中使用 M3 主题:

<style name="AppTheme" parent="Theme.Material3.DayNight">

Then in your layout:然后在你的布局中:

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNav_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.App.BottomNavigationView"

with:和:

<style name="ThemeOverlay.App.BottomNavigationView" parent="">
    <item name="colorSurface">#d1e4ff</item>
    <item name="colorSecondaryContainer">#0061a3</item>
</style>

在此处输入图像描述

在此处输入图像描述

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

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