我在
Android中使用最近由设计库25中的谷歌引入的底部布局导航样式.在我看到的所有教程和问题中,图标中的图像是正常大小,但是我的图像非常小,尽管事实上我保存到drawable文件夹的图像是72×72.这是一个截图:
图标应至少为2,甚至可能是该尺寸的3倍.我该怎么做?这是我在bottom_layout.xml中的代码:
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/menu_home" android:title="test" android:icon="@drawable/tabbarglossary" app:showAsAction="always|withText" /> <item android:id="@+id/menu_search" android:title="test2" android:icon="@drawable/mediationtabbar" app:showAsAction="always|withText" /> <item android:id="@+id/menu_notifications" android:title="test3" android:icon="@drawable/ic_action_name" app:showAsAction="always|withText" /> </menu>
在我的activity_main.xml中:
<android.support.design.widget.BottomNavigationView android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="80dp" android:layout_alignParentBottom="true" android:layout_gravity="bottom" android:layout_marginBottom="0dp" android:layout_marginLeft="0dp" android:layout_marginRight="0dp" android:focusable="false" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" design:menu="@menu/bottom_layout" />
谢谢
解决方法
图标大小在项目布局中硬编码为24dp(参见
design_bottom_navigation_item.xml)
这可以通过编程方式更改:
这可以通过编程方式更改:
BottomNavigationView bottomNavigationView = (BottomNavigationView) activity.findViewById(R.id.bottom_navigation_view); BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0); for (int i = 0; i < menuView.getChildCount(); i++) { final View iconView = menuView.getChildAt(i).findViewById(android.support.design.R.id.icon); final ViewGroup.LayoutParams layoutParams = iconView.getLayoutParams(); final DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); // set your height here layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,32,displayMetrics); // set your width here layoutParams.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,displayMetrics); iconView.setLayoutParams(layoutParams); }
编辑
对于图标覆盖文字的问题:
您可以覆盖底部导航视图的某些默认尺寸.例如高度.
<dimen name="design_bottom_navigation_height" tools:override="true">56dp</dimen>
检查guidelines bottom navigation是否有默认规格.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。