3

I am trying to add DPAD navigation support for my app. However, I found it is not possible to move the focus to the action menu items on Android 5. But it works fine on Android 4.4.4, see attached screenshot below, the robot icon is focused and highlighted. enter image description here

Same code does not work on Android 5.1.1 Nexus7. Does anyone have any idea?

Attached my code and xmls.

MainActivity.java:

package com.example.zzztest;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Menu XML:

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>

    <item
        android:id="@+id/action_asdf"
        android:icon="@drawable/ic_launcher"
        android:title="@string/action_settings"
        app:showAsAction="always"/>
</menu>

Layout XML:

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>
Robin
  • 10,052
  • 6
  • 31
  • 52

1 Answers1

0
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="always"/>

I used app:showAsAction="always". Press Dpad "Menu" Button and it can be selected.

Jason Hoch
  • 805
  • 1
  • 7
  • 7