How to support dpad controls for RecyclerView

后端 未结 3 1504
野性不改
野性不改 2021-02-20 08:53

I am currently trying to port Android mobile app to Android TV. I have a RecyclerView that seems to be displaying correctly in my Android TV app. I am using linearLayout for my

3条回答
  •  盖世英雄少女心
    2021-02-20 09:39

    What my code was having problems doing was giving focus to the first child of the recyclerview. Once it was there it seemed to handle dpad controls well.

    Without seeing more of your code, this is the best suggestion. Please provide your activity and full xml if this doesn't work. Good Luck!

    In your xml:

          
           android:nextFocusDown="@+id/RecyclerView"
    
    
    
       
    

    In your activity:

        public static final int BANNER = 0;
        public static final int RECVIEW1 = 1;
        public static final int RECVIEW2 = 2;
        private static int currFocus = 0;
    
        //you will need to do something similar to this listener for all focusable things
        RecyclerView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    Log.i("ONFOCUSCHANGE- reclist", "focus has changed I repeat the focus has changed! current focus = " + currFocus);
                    if(currFocus != RECVIEW1){
                        currFocus = RECVIEW1;
                        RecyclerView.getChildAt(0).requestFocus();
                    }
                }
            });
    

提交回复
热议问题