android TabHost 如何控制在TabHost中按返回键不会回到主界面?
答案:2 悬赏:30
解决时间 2021-02-01 10:22
- 提问者网友:喵星人荷西
- 2021-01-31 11:32
有A和B两个tab,B中显示省份的list,点击某个省份进入到省对应的城市,城市列表也在tabhost中,但是按back返回键,返回不到省份列表了,直接就回到手机主界面,请问如何控制按返回键不会回到主界面?
最佳答案
- 二级知识专家网友:邪性洒脱
- 2021-01-31 12:44
重载Back键处理函数,例如:
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
File file = new File(strCrtPath);
String strParentPath = file.getParent();
if(strParentPath != null){
AddEachFile(strParentPath);
}
else{
super.onBackPressed();
}
return;
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
File file = new File(strCrtPath);
String strParentPath = file.getParent();
if(strParentPath != null){
AddEachFile(strParentPath);
}
else{
super.onBackPressed();
}
return;
}
全部回答
- 1楼网友:深街酒徒
- 2021-01-31 13:34
你的问题我理解的不是太清楚,但是有可能是这样:嵌入到tabhost里面的activity其实并没有压入activity栈,而是通过一个localactivitymanager来管理。这样你按返回键的时候,实际上调用的还是tabacitivty里面的onkeydown。所以就直接返回主界面了。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯