Message displayed on Toolbar
Messages are being displayed on toolbar rather than under it like they do in case of Actionbar, any help ?
same with me :(
If you are using new themes/toolbars, the positioning requires tweaking.
appMsg.setLayoutParams(getParams());
/**
* The new theme requires some layout tweaking for croutons
*/
public FrameLayout.LayoutParams getParams() {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, getSupportActionBar().getHeight(), 0, 0);
return layoutParams;
}
@matthew-reilly Your solution works but in Pre-Lollipop versions. Is there a solution for 5.x y 6.x Android version? Thanks.
@khirr I would really recommend using Snackbar
@matthew-reilly Thank you but it really necessary for me use it like "notifications" and not just to say a status change.
Finally I found a solution re-using yours:
private FrameLayout.LayoutParams getLayoutParams() {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
int height = 0;
if (mActivity.getSupportActionBar() != null) {
height = mActivity.getSupportActionBar().getHeight();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
height += getStatusBarHeight();
}
layoutParams.setMargins(0, height, 0, 0);
return layoutParams;
}
private int getStatusBarHeight() {
int result = 0;
int resourceId = mActivity.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = mActivity.getResources().getDimensionPixelSize(resourceId);
}
return result;
}