我在Android应用中使用了BottomNavigationbar。当我在平板电脑上运行时,它在bottomnavigationbar中显示非常小的图标。我想增加平板电脑的尺寸。
我试图在可绘制的文件夹中放置不同大小的图标,但问题仍然存在。
main_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundGray"
tools:context="com.shakeel.board.MainActivity">
<FrameLayout
android:id="@+id/fragments_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_nav_bar">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_nav_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="@menu/bottom_navigation_menu"
android:padding="5dp"
android:background="@color/white">
</android.support.design.widget.BottomNavigationView>
bottom_navigation_menu.xml
<item android:id="@+id/nav_home"
android:title="Home"
android:icon="@drawable/home"/>
<item android:id="@+id/nav_favorites"
android:title="Favorite"
android:icon="@drawable/ic_favorite_red_24dp"/>
<item android:id="@+id/nav_shop"
android:title="Shop"
android:icon="@drawable/ic_shopping_basket_black_24dp"/>
<item android:id="@+id/nav_setting"
android:title="Setting"
android:icon="@drawable/ic_settings_black_24dp"/>
MainActivity.class
public class MainActivity extends AppCompatActivity {
BottomNavigationView bootomNavigation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bootomNavigation = findViewById(R.id.bottom_nav_bar);
BottomNavigationViewHelper.removeShiftMode(bootomNavigation);
getSupportFragmentManager().beginTransaction().replace(R.id.fragments_container, new HomeFragment()).commit();
bootomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()){
case R.id.nav_home:
selectedFragment = new HomeFragment();
break;
case R.id.nav_favorites:
selectedFragment = new FavoritesFragment();
break;
case R.id.nav_shop:
selectedFragment = new ShopFragment();
break;
case R.id.nav_setting:
selectedFragment = new SettingFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.fragments_container, selectedFragment).commit();
return true;
}
});
}
}
答案 0 :(得分:0)
您可以从material design页下载图标,选择图标,然后选择Android选项(请参见下图),您将获得一组相同大小的图标,以适应不同的屏幕尺寸。< / p>