'openOptionsMenu() does not work on android TV emulator
I have a menu opening when clicking a button in my view. When I emulate any cell phone, the menu is showing, but when emulating android TV (which I develop the app for), it dosnt show anything when clicking. I also tried to run it on a real androidTV and nothing...
can anyone tell me why?
in my public class CameraActivity extends Activity i have public void SelCursor(View view){
openOptionsMenu();
}
my relevant part from layout 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" />
in activity:
@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);
}
}
}
and menu file:
<?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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
