【问题标题】:clear focus on content when navigation drawer is showed显示导航抽屉时清楚地关注内容
【发布时间】:2014-01-08 17:50:23
【问题描述】:

在具有导航抽屉的 android 活动中清除焦点的最佳方法是什么。

问题在于,当用户选择了一个文本框时,如果您打开导航抽屉后退事件,它不会被抽屉使用,并且导航会后退一步,使抽屉打开。

现在我解决了在活动中使用它的问题,但我想知道是否有人使用我不需要使用 ActionBarDrawerToggle 事件的其他解决方案。

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
    View window = findViewById(R.id.content_frame);
    window.clearFocus();
}

【问题讨论】:

  • 你有没有找到一个干净的解决方案?

标签: android focus navigation-drawer


【解决方案1】:

确实,抽屉在打开时似乎没有焦点,因此不会调用onKeyUp。我在主机活动中检查了这一点,如果活动有一个获得焦点的视图 - EditText 或其他东西,则在 onBackPressed DrawerLayout#hasFocus() 返回 false。

我什至试图弄乱它的descendantFocusability 属性,但没有奏效。我设法用与您类似的方法解决了这个问题:抽屉布局正在请求焦点:

mDrawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
    @Override
    public void onDrawerOpened(View drawerView) {
        mDrawerLayout.requestFocus();
    }
});

您正在从内容 ViewGroup 中清除焦点,但我不确定谁获得了焦点,很可能没有视图。
老实说,这在我看来是 DrawerLayout 中的一个错误,好像它已打开一样,它应该获得焦点。

【讨论】:

    猜你喜欢
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多