在我的android webView中,android操作栏中的后退按钮不起作用,而硬件按钮工作正常,我甚至在操作栏中也有一个菜单按钮。
Java文件
@Bean
public MappingJackson2HttpMessageConverter customJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
objectMapper.configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, true);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setDateFormat(new SimpleDateFormat("dd MMM yyyy hh:mm:ss a"));
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}
答案 0 :(得分:1)
尝试使用 android.R.id.home
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
Toast.makeText(this, "Back Button clicked", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
this.finish();
}
return super.onOptionsItemSelected(item);
}
答案 1 :(得分:0)
使用以下代码。
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.btn_home)
{
onBackPressed();
}
return true;
}