Skip to content

Message displayed on Toolbar #34

Open
@Shahroz16

Description

@Shahroz16

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

Activity

kiratheone

kiratheone commented on Feb 12, 2015

@kiratheone

same with me :(

matthew-reilly

matthew-reilly commented on May 11, 2015

@matthew-reilly

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;
    }
linked a pull request that will close this issue on Oct 15, 2015
khirr

khirr commented on Mar 6, 2016

@khirr

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

matthew-reilly

matthew-reilly commented on Mar 7, 2016

@matthew-reilly

@khirr I would really recommend using Snackbar

khirr

khirr commented on Mar 7, 2016

@khirr

@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;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @matthew-reilly@kiratheone@Shahroz16@khirr

      Issue actions

        Message displayed on Toolbar · Issue #34 · johnkil/Android-AppMsg