0

大家好,这是我的代码。该菜单在我的手机(Android 2.3)上完美运行。但在我的平板电脑(Android 4.0)上,它不显示图标。菜单工作正常。有人可以帮助我吗?为什么会这样?我正在使用Theme_Black_NoTitleBar.AndroidManifest.xml

public final class IntentsDemoActivity extends Activity implements
        OnItemClickListener {

    public static final int ABOUT = 0;
    public static final int INFO = 1;
    public static final int WEBSITE = 2;

    // This is the value of Intent.EXTRA_LOCAL_ONLY for API level 11 and above.
    private static final String EXTRA_LOCAL_ONLY = "android.intent.extra.LOCAL_ONLY";
    private static final String VIDEO_ID = "-Uwjt32NvVA";
    private static final String PLAYLIST_ID = "PLF3DFB800F05F551A";
    private static final String USER_ID = "Google";
    private static final int SELECT_VIDEO_REQUEST = 1000;

    private List<DemoListViewItem> intentItems;

    public boolean onCreateOptionsMenu(android.view.Menu menu) {
        super.onCreateOptionsMenu(menu);
        menu.add(0, ABOUT, 0, "About").setIcon(R.drawable.about);
        menu.add(0, INFO, 0, "Info").setIcon(R.drawable.info);
        menu.add(0, WEBSITE, 0, "Website").setIcon(R.drawable.website);
        return true;
    }

    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        switch (item.getItemId()) {
        case ABOUT:
            Toast.makeText(IntentsDemoActivity.this, "About", Toast.LENGTH_SHORT).show();
            Uri uri = Uri.parse("https://www.google.com/about);
            Intent it = new Intent(Intent.ACTION_VIEW,uri);
            startActivity(it);
            return true;

            case PAGE:
            Toast.makeText(IntentsDemoActivity.this, "Info", Toast.LENGTH_SHORT).show();
            Uri uri = Uri.parse("https://www.google.com/info");
            Intent it = new Intent(Intent.ACTION_VIEW,uri);
            startActivity(it);
            return true;
           case WEBSITE:
          Toast.makeText(IntentsDemoActivity.this, "Webiste", Toast.LENGTH_SHORT).show();
          Uri uri1 = Uri.parse("http://www.google.com/");
            Intent it1 = new Intent(Intent.ACTION_VIEW,uri1);
            startActivity(it1);
          return true;

          }
          return false;
      }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.intents_demo);

        intentItems = new ArrayList<DemoListViewItem>();
        intentItems.add(new IntentItem("X", IntentType.X));
        intentItems.add(new IntentItem("Play Video", IntentType.PLAY_VIDEO));
        intentItems.add(new IntentItem("Open Playlist",
                IntentType.OPEN_PLAYLIST));
        intentItems.add(new IntentItem("Play Playlist",
                IntentType.PLAY_PLAYLIST));
        intentItems.add(new IntentItem("Open User", IntentType.OPEN_USER));
        intentItems.add(new IntentItem("Open Search Results",
                IntentType.OPEN_SEARCH));
        intentItems
                .add(new IntentItem("Upload Video", IntentType.UPLOAD_VIDEO));

        ListView listView = (ListView) findViewById(R.id.intent_list);
        DemoArrayAdapter adapter = new DemoArrayAdapter(this,
                R.layout.list_item, intentItems);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);

        TextView youTubeVersionText = (TextView) findViewById(R.id.youtube_version_text);
        String version = YouTubeIntents.getInstalledYouTubeVersionName(this);
        if (version != null) {
            String text = String.format(
                    getString(R.string.youtube_currently_installed), version);
            youTubeVersionText.setText(text);
        } else {
            youTubeVersionText
                    .setText(getString(R.string.youtube_not_installed));
        }
    }

    public boolean isIntentTypeEnabled(IntentType type) {
        switch (type) {
        case PLAY_VIDEO:
            return YouTubeIntents.canResolvePlayVideoIntent(this);
        case OPEN_PLAYLIST:
            return YouTubeIntents.canResolveOpenPlaylistIntent(this);
        case PLAY_PLAYLIST:
            return YouTubeIntents.canResolvePlayPlaylistIntent(this);
        case OPEN_SEARCH:
            return YouTubeIntents.canResolveSearchIntent(this);
        case OPEN_USER:
            return YouTubeIntents.canResolveUserIntent(this);
        case UPLOAD_VIDEO:
            return YouTubeIntents.canResolveUploadIntent(this);
        }

        return false;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        IntentItem clickedIntentItem = (IntentItem) intentItems.get(position);

        Intent intent;
        switch (clickedIntentItem.type) {
        case X:
            // This will load a picker view in the users' gallery.
            // The upload activity is started in the function onActivityResult.
            intent = new Intent(Intent.ACTION_PICK, null).setType("video/*");
            intent.putExtra(EXTRA_LOCAL_ONLY, true);
            startActivityForResult(intent, SELECT_VIDEO_REQUEST);
            break;

        case PLAY_VIDEO:
            intent = YouTubeIntents.createPlayVideoIntentWithOptions(this,
                    VIDEO_ID, true, false);
            startActivity(intent);
            break;
        case OPEN_PLAYLIST:
            intent = YouTubeIntents.createOpenPlaylistIntent(this, PLAYLIST_ID);
            startActivity(intent);
            break;
        case PLAY_PLAYLIST:
            intent = YouTubeIntents.createPlayPlaylistIntent(this, PLAYLIST_ID);
            startActivity(intent);
            break;
        case OPEN_SEARCH:
            intent = YouTubeIntents.createSearchIntent(this, USER_ID);
            startActivity(intent);
            break;
        case OPEN_USER:
            intent = YouTubeIntents.createUserIntent(this, USER_ID);
            startActivity(intent);
            break;
        case UPLOAD_VIDEO:
            // This will load a picker view in the users' gallery.
            // The upload activity is started in the function onActivityResult.
            intent = new Intent(Intent.ACTION_PICK, null).setType("video/*");
            intent.putExtra(EXTRA_LOCAL_ONLY, true);
            startActivityForResult(intent, SELECT_VIDEO_REQUEST);
            break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent returnedIntent) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
            case SELECT_VIDEO_REQUEST:
                Intent intent = YouTubeIntents.createUploadIntent(this,
                        returnedIntent.getData());
                startActivity(intent);
                break;
            }
        }
        super.onActivityResult(requestCode, resultCode, returnedIntent);
    }

    private enum IntentType {
        X, PLAY_VIDEO, OPEN_PLAYLIST, PLAY_PLAYLIST, OPEN_USER, OPEN_SEARCH, UPLOAD_VIDEO;
    }

    private final class IntentItem implements DemoListViewItem {

        public final String title;
        public final IntentType type;

        public IntentItem(String title, IntentType type) {
            this.title = title;
            this.type = type;
        }

        @Override
        public String getTitle() {
            return title;
        }

        @Override
        public boolean isEnabled() {
            return isIntentTypeEnabled(type);
        }

        @Override
        public String getDisabledText() {
            return getString(R.string.intent_disabled);
        }
    }
}
4

3 回答 3

0

Drawble-ldpi、mdpi、hdpi、xhdpi 文件夹必须保存自己的文件,因此请将同名图标放在不同的文件夹中。我认为您的代码没有错,只有跳蚤错误。如果您要创建不同的视觉效果,您的布局文件也必须位于具有相同名称的不同可绘制文件夹中。

于 2013-03-06T20:08:07.620 回答
0

确保您在所有 Drawable 文件夹中粘贴了相同的图标,即 ldpi、mdpi、hdpi,尤其是平板电脑的 xhdpi。

如果相应文件夹中有所有版本的图标,请发布 menu.xml 文件。

于 2013-03-06T19:29:24.517 回答
0

但在我的平板电脑(Android 4.0)上,它不显示图标。

如果图标位于操作栏的溢出菜单中,则不应显示该图标。溢出菜单是纯文本的。

于 2013-03-06T20:02:51.610 回答