0

I produce the following snackbar with the following code:

Snackbar: Snackbar

Code:

View parentLayout = findViewById(android.R.id.content);
        Snackbar snackbar = Snackbar.make(parentLayout, "Wähle mindestens eine Kategorie aus, um fortzufahren", Snackbar.LENGTH_LONG)
                .setAction("CLOSE", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                    }
                })
                .setActionTextColor(getResources().getColor(android.R.color.holo_purple ));
        snackbar.show();

As you see, the snackbar is pretty big and I actually only want it to be displayed in the area of the red box. Do you know how to adjust that?

Tobi Z
  • 29
  • 2

1 Answers1

0

It must bug around with the other Widgets of the Layout. Try to make only one Button and add Widgets step by step. Then you will find out.

I improved your Code a bit and used one Button and the Snackbar like this:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = findViewById(R.id.button_snackbar);
        button.setOnClickListener(view -> {
            View parentLayout = findViewById(android.R.id.content);
            Snackbar snackbar = Snackbar.make(parentLayout, "Wähle mindestens eine Kategorie aus, um fortzufahren", Snackbar.LENGTH_LONG)
                    .setAction("CLOSE", view1 -> {
                    })
                    .setActionTextColor(getResources().getColor(android.R.color.holo_purple));
            snackbar.show();
        });
    }
}

PROVE:

Snackbar

Ole Pannier
  • 3,208
  • 9
  • 22
  • 33