Я думаю, вы могли бы искать это.Вот быстрый фрагмент, чтобы начать. activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:id="@+id/viewlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemBackground="@color/colorAccent"
android:layout_gravity="bottom"
tools:elevation="2dp"
app:itemTextColor="#fff"
android:layout_alignParentBottom="true"
app:menu="@menu/bottom_menu" />
</RelativeLayout>
Создать файл ресурсов меню внутри res / menu / bottom_menu.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/action_home"
android:enabled="true"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/home"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_msg"
android:enabled="true"
android:icon="@drawable/ic_message_black_24dp"
android:title="@string/msg"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_video"
android:enabled="true"
android:icon="@drawable/ic_ondemand_video_black_24dp"
android:title="@string/video"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_info"
android:enabled="true"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/info"
app:showAsAction="ifRoom" />
</menu>
СоздатьФрагменты для каждого из представлений:
Создание четырех фрагментов с именем Home, Message, Video и Notification.
Реализация OnItemSelectedListener представления BottomNavigation: MainActivity.java:
package net.technxt;
import android.support.annotation.NonNull;
import android.support.design.bottomnavigation.LabelVisibilityMode;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.FrameLayout;
public class MainActivity extends AppCompatActivity {
BottomNavigationView bottomNavigationView;
FrameLayout viewlayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewlayout = (FrameLayout)findViewById(R.id.viewlayout);
bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
final FragmentManager fragmentManager = getSupportFragmentManager();
// Declare fragments here
final Home home = new Home();
final Message msg = new Message();
final Video video = new Video();
final Notification noti = new Notification();
bottomNavigationView.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragment;
switch (item.getItemId()) {
case R.id.action_home:
fragment = home;
setTitle(item.getTitle());
break;
case R.id.action_msg:
fragment = msg;
setTitle(item.getTitle());
break;
case R.id.action_video:
fragment = video;
setTitle(item.getTitle());
break;
case R.id.action_info:
default:
fragment = noti;
setTitle(item.getTitle());
break;
}
fragmentManager.beginTransaction().replace(R.id.viewlayout, fragment).commit();
return true;
}
});
// Set default selection
bottomNavigationView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
bottomNavigationView.setSelectedItemId(R.id.action_home);
}
}
Как создать нижнюю панель навигации для Android?