如何在android中删除底部导航视图的图标动画

编程入门 行业动态 更新时间:2024-10-14 06:24:05
本文介绍了如何在android中删除底部导航视图的图标动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我已经在我的项目中实现了来自设计支持库 25 的底部导航视图.我在视图中有 5 个图标.whenever an icon is selected it's having some animation.但是当 3 个或更少的图标不显示任何动画时.我想删除那个动画,只需要对图标进行一些颜色更改.我怎样才能做到这一点?做了足够的谷歌搜索,但找不到解决方案.请帮忙.谢谢.

解决方案

从这个 thread 中得到了答案.

删除动画或移位模式.

BottomNavigationView 的实现有条件:当超过 3 项时使用移位模式.

<块引用>

创建辅助类

import android.support.design.internal.BottomNavigationItemView;导入 android.support.design.internal.BottomNavigationMenuView;导入 android.support.design.widget.BottomNavigationView;导入 android.util.Log;导入 java.lang.reflect.Field;公共类 BottomNavigationViewHelper {public static void disableShiftMode(BottomNavigationView view) {BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);尝试 {Field shiftMode = menuView.getClass().getDeclaredField("mShiftingMode");shiftMode.setAccessible(true);shiftMode.setBoolean(menuView, false);shiftMode.setAccessible(false);for (int i = 0; i < menuView.getChildCount(); i++) {BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);//不检查RestrictedApiitem.setShiftingMode(false);//再次设置选中的值,因此视图将被更新//不检查RestrictedApiitem.setChecked(item.getItemData().isChecked());}} catch (NoSuchFieldException e) {Log.e("BNVHelper", "无法获取换档模式字段", e);} catch (IllegalAccessException e) {Log.e("BNVHelper", "无法改变移位模式的值", e);}}}

<块引用>

用法

BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_bar);BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);

I have implemented Bottom Navigation View from Design Support Library 25 in my project. I have 5 icons in the view. whenever an icon is selected it's having some animation. But when 3 or fewer icons is not showing any animations. I want to remove that animation and need only some color change for the icon. How can I achieve this? Done enough googling, but couldn't find the solution. Please help. Thanks.

解决方案

got answer from this thread.

To remove animation or shift mode.

Implementation of BottomNavigationView has condition: when there is more than 3 items then use shift mode.

Create helper class

import android.support.design.internal.BottomNavigationItemView; 
import android.support.design.internal.BottomNavigationMenuView; 
import android.support.design.widget.BottomNavigationView; 
import android.util.Log;
import java.lang.reflect.Field;

public class BottomNavigationViewHelper { 
    public static void disableShiftMode(BottomNavigationView view) {
        BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
        try { 
            Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
            shiftingMode.setAccessible(true);
            shiftingMode.setBoolean(menuView, false);
            shiftingMode.setAccessible(false);
            for (int i = 0; i < menuView.getChildCount(); i++) {
                BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
                //noinspection RestrictedApi 
                item.setShiftingMode(false);
                // set once again checked value, so view will be updated 
                //noinspection RestrictedApi 
                item.setChecked(item.getItemData().isChecked());
            } 
        } catch (NoSuchFieldException e) {
            Log.e("BNVHelper", "Unable to get shift mode field", e);
        } catch (IllegalAccessException e) {
            Log.e("BNVHelper", "Unable to change value of shift mode", e);
        } 
    } 
} 

Usage

BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_bar);
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);

这篇关于如何在android中删除底部导航视图的图标动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 01:39:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/993815.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   图标   动画   如何在   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!