Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

@Override
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?

like image 615
Vasil Valchev Avatar asked Dec 15 '22 07:12

Vasil Valchev


2 Answers

For every Snackbar, the Snackbar textview resource id is

    android.support.design.R.id.snackbar_text

And the Snackbar action view resource id is

    android.support.design.R.id.snackbar_action

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 -

@Override
public void onClick(View v) {

    if (v.getId() == android.support.design.R.id.snackbar_action) {

    }
}
like image 173
Shadab Ansari Avatar answered Dec 16 '22 20:12

Shadab Ansari


v.getId()

is always (Reserved) :

android.support.design.R.id.snackbar_action

Doc

like image 33
Hossein Kurd Avatar answered Dec 16 '22 20:12

Hossein Kurd