This back button are added automatically on ActionBar
I want button to run the command below instead.
if (mWebView.canGoBack())
{
mWebView.goBack();
}
else
{
super.onBackPressed();
}
The button is automatically added I didn't use any command I don't know where to place my command can anyone help me?
Try this,
toolbar.setNavigationOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (mWebView.canGoBack())
{
mWebView.goBack();
}
else
{
super.onBackPressed();
}
}
});
try this,
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// todo: goto back activity from here
if (mWebView.canGoBack())
{
mWebView.goBack();
}
else
{
super.onBackPressed();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.