當 Navigation 設定成 Translucent mode 時
snackbar 會跟 navigation bar 重疊
不知道為啥 Google 設計 design library 時沒考慮到這件事
private int mNaturalBarHeight = 0;
int idShowNavigation = Resources.getSystem().getIdentifier("config_showNavigationBar", "bool", "android");
boolean isShowNavigationBar = Resources.getSystem().getBoolean(idShowNavigation);
int navigationId = getContext().getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (isShowNavigationBar && navigationId > 0) {
mNaturalBarHeight = getContext().getResources().getDimensionPixelSize(navigationId);
}
要顯示 snackbar 時,改動 layout parameter
final Snackbar snackbar = Snackbar.make(mFab, R.string.msg_to_show, Snackbar.LENGTH_LONG)
.setAction(R.string.action_to_show, new OnClickListener() {
@Override
public void onClick(View v) {
// TODO: go to something
}
});
View v = snackbar.getView();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) v.getLayoutParams();
layoutParams.bottomMargin = mNaturalBarHeight;
v.setLayoutParams(layoutParams);
snackbar.show();
沒有留言:
張貼留言