openOptionsMenu()在Android TV模拟器上不起作用

时间:2017-06-04 23:24:53

标签: android menu android-tv android-optionsmenu

点击我视图中的按钮后,我打开了一个菜单。 当我模仿任何手机时,菜单显示,但在模拟Android TV(我为其开发应用程序)时,它会在点击时显示任何内容。我也尝试在真正的androidTV上运行它而没有......

谁能告诉我为什么?

public class CameraActivity extends Activity我有public void SelCursor(View view){ openOptionsMenu(); }

我在布局xml中的相关部分:

    <Button
        android:id="@+id/Cursor"
        android:layout_width="108dp"
        android:layout_height="40dip"
        android:layout_gravity="bottom"
        android:onClick="SelCursor"
        android:text="@string/Cursor" />

活动:

  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.poupup_menu, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.green_arrow:
                CustomView.arrow =  BitmapFactory.decodeResource(getResources(), R.drawable.arrow_final);
                return true;
            case R.id.greenarrow2:
                CustomView.arrow =  BitmapFactory.decodeResource(getResources(), R.drawable.arrow4);
                return true;
            case R.id.blackarrow:
                CustomView.arrow =  BitmapFactory.decodeResource(getResources(), R.drawable.black_arrow);
                return true;
            case R.id.purplearrow:
                CustomView.arrow =  BitmapFactory.decodeResource(getResources(), R.drawable.purple_arrow);
                return true;
            case R.id.yellowarrow:
                CustomView.arrow =  BitmapFactory.decodeResource(getResources(), R.drawable.yellow_arrow);
                return true;
            case R.id.whitehand:
                CustomView.arrow =  BitmapFactory.decodeResource(getResources(), R.drawable.white_hand);
                return true;
            case R.id.bluearrow:
                CustomView.arrow =  BitmapFactory.decodeResource(getResources(), R.drawable.blue_arrow);
                return true;
            case R.id.redarrow:
                CustomView.arrow =  BitmapFactory.decodeResource(getResources(), R.drawable.red_arrow);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }


}

和菜单文件:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/green_arrow"
        android:icon="@drawable/arrow_final"
        android:showAsAction="always"
        android:title="@string/green_arrow" />
    <item
        android:id="@+id/greenarrow2"
        android:icon="@drawable/arrow4"
        android:showAsAction="always"
        android:title="@string/green_arrow2"/>/>
    <item
        android:id="@+id/purplearrow"
        android:icon="@drawable/purple_arrow"
        android:showAsAction="always"
        android:title="@string/purple_arrow"/>/>
    <item
        android:id="@+id/yellowarrow"
        android:icon="@drawable/yellow_arrow"
        android:showAsAction="always"
        android:title="@string/yellow_arrow" />/>
    <item
        android:id="@+id/whitehand"
        android:icon="@drawable/white_hand"
        android:showAsAction="always"
        android:title="@string/white_hand" />/>
    <item
        android:id="@+id/blackarrow"
        android:icon="@drawable/black_arrow"
        android:showAsAction="always"
        android:title="@string/black_arrow" />/>
    <item
        android:id="@+id/bluearrow"
        android:icon="@drawable/blue_arrow"
        android:showAsAction="always"
        android:title="@string/blue_arrow" />/>
    <item
        android:id="@+id/redarrow"
        android:icon="@drawable/red_arrow"
        android:showAsAction="always"
        android:title="@string/red_arrow" />/>
</menu>

0 个答案:

没有答案