下面列出了android.view.View#getNextFocusRightId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Focuses the next visible view specified in the <code>view</code>
*
* @param view The view to find the next focus for
*/
protected void focusNext(View view) {
int nextId = view.getNextFocusRightId();
if (nextId == NO_ID) {
return;
}
View nextView = findViewById(nextId);
if (nextView.getVisibility() != View.VISIBLE) {
focusNext(nextView);
return;
}
nextView.requestFocus();
currentFocus = nextView;
buttonFocusChangeListener.onFocusChange(nextView, true);
}
/**
* 向右移动焦点时, 下一个获取焦点的 View id
* @param view {@link View}
* @return 向右移动焦点时, 下一个获取焦点的 View id
*/
public static int getNextFocusRightId(final View view) {
if (view != null) {
return view.getNextFocusRightId();
}
return 0;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
//Filter for LG devices, see https://code.google.com/p/android/issues/detail?id=78154
if ((keyCode == KeyEvent.KEYCODE_MENU) &&
(Build.VERSION.SDK_INT <= 16) &&
(Build.MANUFACTURER.compareTo("LGE") == 0)) {
openOptionsMenu();
return true;
}
View v = getCurrentFocus();
if (v == null)
return super.onKeyUp(keyCode, event);
if ((mActionBarIconId == -1) &&
(v.getId() == -1) &&
(v.getNextFocusDownId() == -1) &&
(v.getNextFocusUpId() == -1) &&
(v.getNextFocusLeftId() == -1) &&
(v.getNextFocusRightId() == -1)) {
mActionBarIconId = Util.generateViewId();
v.setId(mActionBarIconId);
v.setNextFocusUpId(mActionBarIconId);
v.setNextFocusDownId(mActionBarIconId);
v.setNextFocusLeftId(mActionBarIconId);
v.setNextFocusRightId(R.id.ml_menu_search);
if (AndroidUtil.isHoneycombOrLater())
v.setNextFocusForwardId(mActionBarIconId);
if (findViewById(R.id.ml_menu_search) != null)
findViewById(R.id.ml_menu_search).setNextFocusLeftId(mActionBarIconId);
}
return super.onKeyUp(keyCode, event);
}