I have tried every possible way that I can think of to make buttons on a fragment selectable with a D-pad to no avail.
The buttons on a fragment in the layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/imageButtonCopyAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_copy"
android:layout_alignParentTop="true"
android:focusedByDefault="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:contentDescription="Copy all"
android:onClick="@{(v)->textForEmailWindowFragment.onClick(v)}"
android:nextFocusRight="@id/imageButtonSave"
/>
<ImageButton
android:id="@+id/imageButtonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/imageButtonCopyAll"
android:contentDescription="@string/save"
android:focusable="true"
android:focusableInTouchMode="true"
android:onClick="@{(v)->textForEmailWindowFragment.onClick(v)}"
app:srcCompat="@drawable/ic_action_save" />
</RelativeLayout>
Java code:
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
TextForEmailWindowFragment tfewFragment = TextForEmailWindowFragment.newInstance();
fragmentTransaction.add(R.id.relativeLayoutMain, tfewFragment);
fragmentTransaction.addToBackStack("foo");
fragmentTransaction.commit();
Everything works flawlessly with a touchscreen or a mouse. The buttons can be tapped or clicked. However, the buttons never get the focus, so a D-pad cannot select them. The focus is always on the elements of the calling activity's layout beneath the fragment. Could anyone offer a tip on the cause?