Vasil Valchev Vasil Valchev - 1 year ago 89
Android Question

Snackbar action getView()

in my Activity I have implement OnClickListener interface

MainActivity extends AppCompatActivity implements View.OnClickListener

init snackbar like this:

snackbar = Snackbar.make(view, R.string.msg, Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.action_undo, this);

but I cannot handle it on implemented OnClickListener interface method

public void onClick(View v) {
// this not work!
// snackbar id is different from snackbar action id
if (v.getId() == snackbar.getView().getId()) {


Someone know how to get action view from snackbar?

Answer Source

For every Snackbar, the Snackbar textview resource id is

And the Snackbar action view resource id is

If I correctly understood your question, you want to get the Snackbar action resource id. you can easily get that as I mentioned above and in onClick() , you can use it like -

public void onClick(View v) {

    if (v.getId() == {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download