public interface BackButtonBlocker{ void onBackPressed();}
BackButtonBlocker接口用于回调。我的片段实现了BackButtonBlocker,但有时onBackPressed不会发生(onKeyUp也是如此)。
当我打开导航抽屉时,onBackPressed和完整逻辑正好工作。
为什么活动会失去焦点?
android.support.v4.app.Fragment
openPanel: function() {
// Trying to call general-element _openPanel method
$$('specific-element').$$('general-element')._openPanel();
}
答案 0 :(得分:0)
从super.onBackPressed();
else{}
答案 1 :(得分:0)
我所做的是,我没有实现任何处理后退的界面,见下文。
@Override
public void onBackPressed() {
if (getDrawerLayout().isDrawerOpen(GravityCompat.START)) {
closeLeftMenu();
}
else {
if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
super.onBackPressed();
} else {
finish(); // Means it is home and you can exit it from here.
}
}}
When drawer is open just close it then use your code.
答案 2 :(得分:0)
我通过在Mainactivity的容器视图
上添加setFocusableInTouchMode(true); requestFocus();
来修复此问题