【问题标题】:Navigating in View with RecyclerView使用 RecyclerView 在视图中导航
【发布时间】:2018-11-01 06:23:21
【问题描述】:

我的应用程序同时支持 Android TV 和智能手机

一般来说,通过应用程序导航很好,但我对这样的布局有一个问题

View with Buttons
RecyclerView
View with Buttons

我想用方向键(或箭头)浏览此视图,但 Recycler 有点问题。

我可以通过设置从上视图和下视图设置对回收器的关注

android:nextFocusDown="@+id/recycler"  

并使回收器可聚焦,但现在我想“进入”回收器,例如使用 D-pad OK(或 Enter)

如何在 imeInputType (ok/enter) 上将焦点从 recycler 移到 recycler 的第一个子级,并将单击(back/esc)的焦点从子级重新设置回其父级 recycler?

【问题讨论】:

  • 我认为您需要一种程序化方法。你试过了吗?

标签: android android-recyclerview android-tv d-pad


【解决方案1】:

您正在以编程方式添加子视图,因此您需要以编程方式设置下一个焦点视图。

类似的东西

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {

            View child = mRecyclerView.getLayoutManager().getChildAt(0);
            child.setFocusable(true);
            child.setFocusableInTouchMode(true);
            child.requestFocus();

            // to check current focused view
            // View focused = getActivity().getCurrentFocus();

            return true;
        }
        return false;
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 2019-02-21
    • 2017-07-15
    • 1970-01-01
    相关资源
    最近更新 更多