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?
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) {
}
}
v.getId()
is always (Reserved) :
android.support.design.R.id.snackbar_action
Doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With