简体   繁体   中英

alert_dialog_icon not found with drawable

I am trying to do an example of menu item

MenuItem mnu1 = menu.add(0, 0, 0, "Item 1");
    {
        mnu1.setAlphabeticShortcut('a');
        mnu1.setIcon(R.drawable.alert_dialog_icon);            
    }

But in my eclipse i am not able to find alert_dialog_icon . Can anybody please explain me why this is happening. I am able to use only ic_launcher .

You need to check 3 things.

First Check whether alert_dialog_icon exists in any drawable folder or not.

Secondly Check which R Class you have imported.

Third Clean your Project and build the Project. This time it should work if above both are fine.

您的项目中(或链接到您的项目)需要有一个名称为alert_dialog_icon的可绘制资源(PNG或XML可绘制)。

As explained by others you may need to add your own images to project.

BUT ...

If you don't want to add your own resource to the "res" folder (for example - you're just trying and testing stuff) you can use some of the resources that come with Android - just use the "android.R.drawable.*" ... although it is not recommended - some of those images may become unavailable (which I doubt) in the distant future - but for testing is fine.

Her is an example ...

mnu1.setIcon(android.R.drawable.ic_dialog_alert);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM