I\'m simply calling from my Activity
:
Toast.makeText(this, \"This is a toast\", Toast.LENGTH_SHORT).show()
But the result is a
This situation occurs because in the horizontal screen state, the width of the navigation bar will also be calculated, regardless of whether the navigation bar is hidden or not, so you can subtract half the width of the navigation bar.
toast.setGravity(Gravity.CENTER, getNavigationBarHeight() / 2, 0);
private int getNavigationBarHeight() {
Resources resources = this.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}