//依赖
implementation 'com.android.support:design:27.1.1'//底部导航栏
<android.support.design.widget.BottomNavigationView android:id="@+id/navigation" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="0dp" android:layout_marginStart="0dp" android:background="?android:attr/windowBackground" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:menu="@menu/navigation" /> //strings <string name="title_home">推荐</string> <string name="title_dashboard">段子</string> <string name="title_notifications">视频</string> //新建selector 这是“raw_1500085367”drawable文件夹下的图片 <item android:state_checked="true" android:drawable="@drawable/raw_1500085367"/> <item android:drawable="@drawable/raw_1500083878"/> <item android:state_checked="false" android:drawable="@drawable/raw_1500083878"/> //新建selector //这是“raw_1500085899”drawable文件夹下的图片 <item android:state_checked="true" android:drawable="@drawable/raw_1500085899"/> <item android:drawable="@drawable/raw_1500085327"/> <item android:state_checked="false" android:drawable="@drawable/raw_1500085327"/> //新建selector //这是“raw_1500086067”drawable文件夹下的图片 <item android:state_checked="true" android:drawable="@drawable/raw_1500086067"/> <item android:drawable="@drawable/raw_1500083686"/> <item android:state_checked="false" android:drawable="@drawable/raw_1500083686"/> //在menu文件夹下新建navigation.xml <item android:id="@+id/navigation_home" android:icon="@drawable/sele_tuijian" android:title="@string/title_home" /> <item android:id="@+id/navigation_dashboard" android:icon="@drawable/sele_duanzi" android:title="@string/title_dashboard" /> <item android:id="@+id/navigation_notifications" android:icon="@drawable/sele_shipin" android:title="@string/title_notifications" /> //MainActivity public class MainActivity extends AppCompatActivity { private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.navigation_home: return true; case R.id.navigation_dashboard: return true; case R.id.navigation_notifications: return true; } return false; } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); }