如何找出目前关注的视图?

Jac*_*nkr 14 android android-layout

我的应用程序使用键盘控制和左右移动时,我注意到,偶尔你会得到什么,我会称其为"神秘视图" -我这样说是因为没有看到似乎被选中,但没有任何可见的或者集中

有什么方法可以找出我在任何特定时间关注的内容吗?例如.触发视图选择等的监听器

谢谢

**编辑 - ntc的一些代码**

LinearLayout col1 = (LinearLayout)findViewById(R.id.col1);
Button btn = new Button(this);
btn.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        LinearLayout col1 = (LinearLayout)findViewById(R.id.col1);
        if(col1.getFocusedChild() != null) {
            Log.d(TAG, col1.getFocusedChild().toString());
        }
    }
});
col1.addChild(btn);
Run Code Online (Sandbox Code Playgroud)

Haf*_*hor 27

getWindow().getCurrentFocus();
Run Code Online (Sandbox Code Playgroud)

  • 这对我不起作用..?“getWindow().getCurrentFocus()”总是返回空值。 (2认同)