简体   繁体   English

使用drawable找不到alert_dialog_icon

[英]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 . 但是在日食中,我无法找到alert_dialog_icon Can anybody please explain me why this is happening. 谁能解释一下为什么会这样。 I am able to use only ic_launcher . 我只能使用ic_launcher

You need to check 3 things. 您需要检查3件事。

First Check whether alert_dialog_icon exists in any drawable folder or not. 首先检查任何drawable文件夹中是否存在alert_dialog_icon

Secondly Check which R Class you have imported. 其次,检查您导入了哪个R类。

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. 如果您不想将自己的资源添加到“ res”文件夹中(例如-您只是在尝试和测试东西),则可以使用Android随附的一些资源-只需使用“ android.R”即可。 drawable。*”。尽管不建议这样做-其中一些图像在遥远的将来可能会变得不可用(我对此表示怀疑)-但可以进行测试。

Her is an example ... 她是一个例子...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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