Get bottom navigation bar size for toasts

This commit is contained in:
M66B 2021-01-04 16:18:08 +01:00
parent 7e6c18e21e
commit c2470e781c
1 changed files with 11 additions and 2 deletions

View File

@ -49,9 +49,18 @@ public class ToastEx extends Toast {
tv.setText(text);
toast.setView(view);
toast.setDuration(duration);
// <dimen name="design_bottom_navigation_height">56dp</dimen>
int dp = Helper.dp2pixels(context, 2 * 56);
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, dp);
int resId = context.getResources().getIdentifier(
"design_bottom_navigation_height", "dimen", context.getPackageName());
int px = Helper.dp2pixels(context, 2 * 56);
if (resId > 0)
try {
px = 2 * context.getResources().getDimensionPixelSize(resId);
} catch (Throwable ex) {
Log.e(ex);
}
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, px);
return toast;
}