SnackBar is shown above what I need

0

I'm having a big problem with a snackbar, it turns out that I created a personalized follow-up of some tutorials I found on the internet, everything is perfect, until it has to be shown, I tell you a little more and I go to the error.

From a button I create and I throw the 'SB', this button is in a fragment and with this I throw it

CustomSnackbar.make(getActivity().findViewById(R.id.v_principal),CustomSnackbar.LENGTH_SHORT).show();

And so it is looking:

It looks much higher than my TabLayout, and the idea is that it looks stuck .. Now you're looking at a transparency because I assign that to you, but it's actually showing a dark gray.

This is my SB class

public class CustomSnackbar extends BaseTransientBottomBar<CustomSnackbar> {

private CustomSnackbar(ViewGroup parent, View content, ContentViewCallback callback) {
    super(parent, content, callback);
}

public static CustomSnackbar make(@NonNull ViewGroup parent,  int duration) {
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    final View content = inflater.inflate(R.layout.custom_snackbar, parent, false);
    final ContentViewCallback viewCallback = new ContentViewCallback(content);
    final CustomSnackbar customSnackbar = new CustomSnackbar(parent, content, viewCallback);
    customSnackbar.getView().setPadding(0, 0, 0, 0);
    customSnackbar.getView().setBackgroundColor(parent.getContext().getResources().getColor( R.color.transparente));
    customSnackbar.setDuration(duration);
    return customSnackbar;
}


public CustomSnackbar setAction(CharSequence text, final View.OnClickListener listener) {
    Button actionView = (Button) getView().findViewById(R.id.snackbar_action);
    actionView.setText(text);
    actionView.setVisibility(View.VISIBLE);
    actionView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            listener.onClick(view);
            // Now dismiss the Snackbar
            dismiss();
        }
    });
    return this;
}

private static class ContentViewCallback implements BaseTransientBottomBar.ContentViewCallback {

    private View content;

    public ContentViewCallback(View content) {
        this.content = content;
    }

    @Override
    public void animateContentIn(int delay, int duration) {
        ViewCompat.setScaleY(content, 0f);
        ViewCompat.animate(content).scaleY(1f).setDuration(duration).setStartDelay(delay);
    }

    @Override
    public void animateContentOut(int delay, int duration) {
        ViewCompat.setScaleY(content, 1f);
        ViewCompat.animate(content).scaleY(0f).setDuration(duration).setStartDelay(delay);
    }
}

Please, I do not know what to do anymore, try everything

Thank you!

    
asked by LcsGrz 27.10.2018 в 08:29
source

1 answer

0

The problem has to do with the google library, the white space behind the Snackbar is the height of our navigation buttons, to correct it and do the following:

I get the top of the bar

    public static void obtenerAltoNavbar(Context c) {
    Resources resources = c.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");

    navBar = ((id > 0 && resources.getBoolean(id))) ? resources.getDimensionPixelSize(resourceId) : 0; 
// Guardo el alto de la barra de navegacion en una variable
}

Then, rest at the lower edge of the snackbar the variable

        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) customSnackbar.getView().getLayoutParams();
    params.setMargins(0, 0, 0, 0 - **navBar**);
    params.gravity = Gravity.BOTTOM;
    customSnackbar.getView().setLayoutParams(params);

And that's it! : D

    
answered by 03.12.2018 / 21:09
source