Android的ActionBarSherlock在顶部图标返回 [英] Android ActionBarSherlock On Top Icon Back
本文介绍了Android的ActionBarSherlock在顶部图标返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让我的前操作栏图标,让用户返回到previous屏幕。我试图执行C $ CS这些$。但没有一个是工作。任何人都可以请指导我在此。我知道这看起来很简单,我是新来的机器人。下面是我的codeS。
问题:当我点击的图标按钮,它只是清除我的屏幕,而无需到previous屏幕
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.view_item);
checkInternetConnection();
getSupportActionBar()setDisplayHomeAsUpEnabled(真)。 //< - 这
@覆盖
公共布尔onOptionsItemSelected(菜单项项)
{
开关(item.getItemId())
{
案例android.R.id.home:
意向意图=新的意图(这一点,SingleViewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(意向);
返回true;
默认:
返回super.onOptionsItemSelected(项目);
}
}
解决方案
这是我做的方式:
@覆盖
公共布尔onOptionsItemSelected(菜单项项){
开关(item.getItemId()){
案例android.R.id.home:
在操作栏中//应用程序图标点击;回家
意向意图=新的意图(这一点,main.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(意向);
打破;
}
返回true;
}
I'm trying to make my top action bar icon to allow users to go back to previous screen. I tried to implement these codes. But none are working. Can anyone please guide me on this. I know this looks simple, I'm new to android . Below are my codes.
Problem : When i tap on the icon button it just cleared my screen without going to the previous screen.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_item);
checkInternetConnection();
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //<--THIS
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case android.R.id.home:
Intent intent = new Intent(this, SingleViewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
解决方案
This is the way I do it:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
Intent intent = new Intent(this, main.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
break;
}
return true;
}
这篇关于Android的ActionBarSherlock在顶部图标返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文