问题描述
限时送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:关键词]
发布评论