2
我正在開發用於chromecast的鈦android模塊,爲此我試圖創建一個菜單欄。 下面的代碼是我使用創建菜單:MenuItem返回null
protected Menu newMenuInstance(Context context) {
try {
Class <? > menuBuilderClass = Class.forName("com.android.internal.view.menu.MenuBuilder");
Constructor <? > constructor = menuBuilderClass.getDeclaredConstructor(Context.class);
return (Menu) constructor.newInstance(context);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
現在,我在下面的代碼膨脹的菜單欄:
@Kroll.method
public void castButtonLoader() {
Menu menu = newMenuInstance(TiApplication.getAppCurrentActivity());
Log.i("menu ", "Menu instance created " + menu);
int menuId = TiApplication.getAppRootOrCurrentActivity()
.getResources()
.getIdentifier("main", "menu",
TiApplication.getInstance().getPackageName());
Log.i("menu ID", "Menu id get =" + menuId);
MenuInflater inflater = TiApplication.getAppCurrentActivity()
.getMenuInflater();
inflater.inflate(menuId, menu);
MenuItem mediaRouteMenuItem;
mediaRouteMenuItem = menu.findItem(menuId);
Log.i("MediaRoute ", " Media route menu item ref =" + mediaRouteMenuItem);
MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem);
Log.i("MediaRouteActionProvider ", " MediaRouteActionProvider ref =" + mediaRouteActionProvider);
// Set the MediaRouteActionProvider selector for device discovery.
mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector);
}
現在,在菜單項,它返回NULL。任何形式的幫助表示讚賞。 謝謝。