0

I'm developing an app can visible Direction pad on the screen, but I don't know how to handle or override action like UP, DOWN, LEFT, RIGHT to focus the next view (like some buttons in image below).

Here are image description

James Z
  • 12,209
  • 10
  • 24
  • 44
Phạm Thanh
  • 1
  • 1
  • 2

2 Answers2

0

Set this tow attributes for your view items :

  1. android:focusableInTouchMode="true"
  2. android:background="@drawable/bg_view"

where bg_view.xml is :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
    <shape android:shape="rectangle">
        <stroke android:width="2dp" android:color="@android:color/white" />
        <solid android:color="#1F1F3E" />
    </shape>
</item>
<item>
    <shape>
        <solid android:color="#1F1F3E" />
    </shape>
</item>
Hossein
  • 439
  • 3
  • 9
0

I found a solution to what I need here Android simulate key press . Use Instrumentation class to sendKeyEvent.

Phạm Thanh
  • 1
  • 1
  • 2