在Android應(yīng)用中添加底部導(dǎo)航欄可以通過以下步驟實(shí)現(xiàn):
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home"
android:title="Home" />
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_dashboard"
android:title="Dashboard" />
<item
android:id="@+id/navigation_notifications"
android:icon="@drawable/ic_notifications"
android:title="Notifications" />
</menu>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="@menu/bottom_navigation_menu" />
BottomNavigationView bottomNavigation = findViewById(R.id.bottom_navigation);
bottomNavigation.setOnNavigationItemSelectedListener(item -> {
switch (item.getItemId()) {
case R.id.navigation_home:
// 處理點(diǎn)擊Home菜單項(xiàng)的邏輯
return true;
case R.id.navigation_dashboard:
// 處理點(diǎn)擊Dashboard菜單項(xiàng)的邏輯
return true;
case R.id.navigation_notifications:
// 處理點(diǎn)擊Notifications菜單項(xiàng)的邏輯
return true;
default:
return false;
}
});
通過以上步驟,你可以在Android應(yīng)用中添加底部導(dǎo)航欄,并實(shí)現(xiàn)相應(yīng)的點(diǎn)擊事件處理邏輯。