明确重点内容时,​​导航抽屉显示 [英] clear focus on content when navigation drawer is showed

查看:130
本文介绍了明确重点内容时,​​导航抽屉显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是明确的焦点,有一个抽屉式导航栏中的一个机器人活动的最佳方式。

这是当用户有一个文本框选择,如果你打开​​导航抽屉它不是由抽屉消耗的背部事件,导航追溯到一步离开抽屉打开的问题。

现在我解决上的活动用这个,但我想知道是否有人使用其他的解决方案,在这里我就不需要使用ActionBarDrawerToggle事件。

  / **当抽屉处于完全开放的状态,先后落户调用。 * /
公共无效onDrawerOpened(查看drawerView){
    视图窗口= findViewById(R.id.content_frame);
    window.clearFocus();
}


解决方案

事实上,它似乎它打开时,抽屉没有焦点所以它的的onkeyup 将不调用。我在主机活动,并在 onBack pressed DrawerLayout#hasFocus()如果活动返回false选中此有获得焦点的视图 - 一个EditText或别的东西。

我甚至试图搞乱与 descendantFocusability 属性和没有工作。我设法用类似的方法解决这个问题,你做的事:抽屉布局要求重点:

  mDrawerLayout.setDrawerListener(新DrawerLayout.SimpleDrawerListener(){
    @覆盖
    公共无效onDrawerOpened(查看drawerView){
        mDrawerLayout.requestFocus();
    }
});

您正在清理从内容ViewGroup中的重点,但我不知道谁获得焦点的话,最有可能没有任何看法。

老实说,这似乎是我DrawerLayout一个错误,如果它是打开,它应该焦点上涨。

What would be the best way to clear the focus in an android activity having a navigation drawer.

The problem it's that when the user has a textbox selected, if you open the navigation drawer the back event it's not consumed by the drawer, and the navigation goes back one step leaving the drawer opened.

Right now I solved using this on the activity, but i would like to know if someone use another solution where i don't need to use the ActionBarDrawerToggle events.

/** 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();
}

解决方案

Indeed it seems the drawer doesn't have focus when it's opened so it's onKeyUp won't be called. I checked this in the host activity and in onBackPressed DrawerLayout#hasFocus() returns false if the activity has a view that gained focus - an EditText or something else.

I even tried to mess up with its descendantFocusability property and that didn't work. I managed to fix this with a similar approach as you did: the drawer layout is requesting the focus:

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

You are clearing the focus from content ViewGroup, but I am not sure who gets the focus then, most probably no view.
Honestly speaking, this seems to me a bug in DrawerLayout as if it's opened, it should have the focus gained.

这篇关于明确重点内容时,​​导航抽屉显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆