Search code examples
androidandroid-tv

Selection button does not work in Android TV


I do not understand why this layoutcan not be selected anything in android tv.

it's not possible select any button or whiget, or insert text. Please help me, and if you can and tell the reason.

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/bTextUrl"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:background="#faf6f6"
    android:layout_marginTop="60dp" />

<Button
    android:layout_width="@dimen/latimea_button_send_tv"
    android:layout_height="@dimen/inaltimea_button_send_tv"
    android:text="@string/button_send_android_tv"
    android:id="@+id/bSendUrl"
    android:background="@drawable/button_send_tv"
    android:layout_below="@+id/bTextUrl"
    android:layout_alignParentStart="true"
    android:layout_marginTop="35dp" />

<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bShare"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right|end"
    android:src="@android:drawable/ic_menu_share"
    app:elevation="6dp"
    app:borderWidth="0dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true" />

Solution

  • Firstly, you have to keep focus of any one of items (i.e. Button, TextView, etc.) as below. And also, you have to apply it's nextFocusDown, nextFocusLeft, nextFocusRight & nextFocusUp properties. So it will fire it's releveant event when you click TV remote navigation buttons.

    Add request focus to your edit text like this,

    <EditText
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/bTextUrl"
       android:layout_alignParentTop="true"
       android:layout_alignParentStart="true"
       android:layout_alignParentEnd="true"
       android:background="#faf6f6"
       android:layout_marginTop="60dp"
       android:nextFocusDown="@+id/bSendUrl">
    
       <requestFocus></requestFocus>
    </EditText>   
    
    <Button
       android:layout_width="@dimen/latimea_button_send_tv"
       android:layout_height="@dimen/inaltimea_button_send_tv"
       android:text="@string/button_send_android_tv"
       android:id="@+id/bSendUrl"
       android:background="@drawable/button_send_tv"
       android:layout_below="@+id/bTextUrl"
       android:layout_alignParentStart="true"
       android:layout_marginTop="35dp" />
    </Button>
    

    And after that, you can add more properties like nextFocusDown, nextFocusLeft, nextFocusRight, nextFocusUp to focus next item.