我正在尝试检查一个非常大的Android(亚马逊火电视)活动的代码,但我一直在运行的应用程序中失去焦点,我不知道正在关注哪个元素。
我正在寻找一种方式(这是一个应用程序,一个开发人员设置 - 显示布局限制接近 - 或者我可以在活动中编写代码)以查看正在聚焦的视图,而无需更改布局(每个视图的选择器。
你有什么建议?
答案 0 :(得分:1)
Activity
有一个名为getCurrentFocus()
的方法。
如果以上内容不起作用,也许您可以在所有hasFocus()
上致电Views
。我想这个方法看起来像这样:
public View getFocusedView(View layout)
{
View focusedView = null;
// Note: I'm not sure if FOCUS_DOWN is the right one to use here
// so you may want to see the other constants offered
ArrayList<View> views = layout.getFocusables(View.FOCUS_DOWN)
for(View v: views)
{
if(v.hasFocus())
{
focusedView = v;
}
}
return focusedView;
}