implementation ‘com.google.android.material:material:1.1.0-alpha08’
导入material的样式
<?xml version="1.0" encoding="utf-8"?>
<androidx.viewpager.widget.ViewPager
android:id="@+id/mainViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tabs_rg"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginBottom="2dp"
app:itemIconTint="@color/tab_text_color_selector"
app:itemTextColor="@color/tab_text_color_selector"
android:background="#fff"
app:menu="@menu/navigation"
app:labelVisibilityMode="labeled">
</com.google.android.material.bottomnavigation.BottomNavigationView>
然后再layout的menu下新建个xml 内容如下 <?xml version="1.0" encoding="utf-8"?>
//这个是退出了 但是还在后台运行
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) {
Intent home = new Intent(Intent.ACTION_MAIN);
home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
home.addCategory(Intent.CATEGORY_HOME);
startActivity(home);
return true;
}
return super.onKeyDown(keyCode, event);
}
}
有点多 但是不难 主要是为了底部的红点 所以选择了这个 方案
人要耐得住寂寞,才能守得住繁华。人生最痛苦的就是拿不起放不下,不属于自己的快乐,及时放手也许是一种解脱,生活中没有谁对谁错,只有适不适合。当发现很多已经改变,更要面对的是事实。