我需要找出是否有任何视图集中在活动中,以及它是什么视图。该怎么做呢?
发布于 2011-03-18 20:55:13
在Activity上调用getCurrentFocus()
。
发布于 2014-01-10 19:50:58
从活动的源头:
/**
* Calls {@link android.view.Window#getCurrentFocus} on the
* Window of this Activity to return the currently focused view.
*
* @return View The current View with focus or null.
*
* @see #getWindow
* @see android.view.Window#getCurrentFocus
*/
public View getCurrentFocus() {
return mWindow != null ? mWindow.getCurrentFocus() : null;
}
发布于 2014-09-03 14:10:57
由于某种原因,getCurrentFocus()方法不再可用;可能它已经被弃用了,这里是可行的替代方法:
View focusedView = (View) yourParentView.getFocusedChild();
https://stackoverflow.com/questions/5352209
复制相似问题