一. Toolbar
-
Style
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<......>
</style>
<style name="AppTheme.NoActionBar">
<item name="android:fitsSystemWindows">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style> -
BaseActivity
4.4兼用占用式
6.0字体明暗配置
private void occupyStatusBar() {
//占用状态栏:相应Style:fitsSystemWindows = false, toolbar需要添加状态栏高度
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//占用虚拟按键栏
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//6.0+ : 改变状态栏字体颜色(此处的颜色应该等同于主题色或状态栏的颜色)
if (isLightColor(getResources().getColor(R.color.colorPrimary))) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
}
private boolean isLightColor(int color) {
return ColorUtils.calculateLuminance(color) >= 0.5;
}
- XML
<!--占用式:自定义高度、内容-->
<!--1.android:fitsSystemWindows="true"(状态栏控件填充)-->
<!--2.android:minHeight="?attr/actionBarSize"(最小高度可修改)-->
<!--3.app:titleMargin="0dp"(布局居中)-->
<!--4.app:contentInsetStart="0dp"(去除右边空隙)-->
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="68dp"
app:titleMargin="0dp"
android:minHeight="?attr/actionBarSize">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 自定义内容 -->
</RelativeLayout>
</android.support.v7.widget.Toolbar>
二. BottomNavigationView
- 显示文字
@SuppressLint("RestrictedApi")
public class BottomNavigationViewHelper {
@SuppressLint("WrongConstant")
public static void disableShiftMode(BottomNavigationView view) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
try {
menuView.setLabelVisibilityMode(1);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
item.setShifting(false);
}
} catch (Exception e) { }
}
}
BottomNavigationViewHelper.disableShiftMode(mNavigationBar);
-
取消字体动画
创建values/values.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="design_bottom_navigation_active_text_size">12dp</dimen>
<dimen name="design_bottom_navigation_text_size">12dp</dimen>
</resources>
- 取消点击波纹
<com.google.android.material.bottomnavigation.BottomNavigationView
...
app:itemBackground="@android:color/transparent"
.../>
网友评论