Android-AppMsg icon indicating copy to clipboard operation
Android-AppMsg copied to clipboard

Message displayed on Toolbar

Open Shahroz16 opened this issue 11 years ago • 5 comments

Messages are being displayed on toolbar rather than under it like they do in case of Actionbar, any help ?

Shahroz16 avatar Jan 14 '15 14:01 Shahroz16

same with me :(

kiratheone avatar Feb 12 '15 06:02 kiratheone

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 avatar May 11 '15 18:05 matthew-reilly

@matthew-reilly Your solution works but in Pre-Lollipop versions. Is there a solution for 5.x y 6.x Android version? Thanks.

khirr avatar Mar 06 '16 03:03 khirr

@khirr I would really recommend using Snackbar

matthew-reilly avatar Mar 07 '16 21:03 matthew-reilly

@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;
    }

khirr avatar Mar 07 '16 21:03 khirr