在Android的选项菜单舒展本地图标填写菜单项,晦涩题名 [英] Local icons in Android Options Menu stretch to fill menu item, obscure Title

查看:130
本文介绍了在Android的选项菜单舒展本地图标填写菜单项,晦涩题名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的,所以链接和图像这里

我可能会做出愚蠢的错误...希望能找出是什么。

I'm likely making a silly mistake... hoping to find out what that is.

我想在我的应用程序的选项菜单使用一些标准的菜单图标(ic_menu_refresh等)。我想设置的图标在菜单中的XML文件。我说我可以用下面的几个地方读:

I'd like to use a few of the standard menu icons (ic_menu_refresh, etc.) in my app's Options Menu. And I'd like to set the icons in the xml file for the menu. I read in a few places that I can use the following:

<item android:id="@+id/quit"
      android:icon="@android:drawable/ic_menu_close_clear_cancel"
      android:title="Quit" />

要在我的菜单中退出按钮。这很好地工作。不过,我也想使用一些其他的图标,如ic_menu_stop.png,这显然是不公开的 [链接1] 。另外,我读过在一些地方,这不是一个好主意引用内部图形像 [链接2] 。同样,我不想用星号替代方法的 [LINK3] 以允许访问私有资源。所提供的解决方案是使可绘的本地副本。

to make a quit button in my menu. And this works nicely. However, I'd also like to use some other icons, like ic_menu_stop.png, which are apparently "not public" [link1]. Also, I've read in a few places that it's not a great idea to "reference internal graphics like that" [link2]. Likewise, I don't want to use the asterisk workaround [link3] to allow access to private resources. The solution offered is to make a local copy of the drawables.

所以我复制的图像文件,我从Ç想:\\ ... \\ Android的8 \\ DATA \\水库\\绘制,华电国际到我的项目的水库\\绘制文件夹,然后改变了上述的XML:

So I copied the image files I wanted from C:\...\android-8\data\res\drawable-hdpi into my project's res\drawable folder, and then changed the above xml to:

<item android:id="@+id/quit"
      android:icon="@drawable/ic_menu_close_clear_cancel"
      android:title="Quit" />

然而,这将导致图标伸展(我相信图标被拉伸 - 而不是简单的一个更大的(华电国际)图像文件 - 因为它是有点模糊),要么晦涩或排挤标题文本,所以我看到的是过大的,模糊的图标。当然,我也尝试复制从图标绘,MDPI 文件夹:使用于mdpi图标不会遮挡的称号,但图标是slighlty矮小和模糊。

However, this causes the icon to stretch (I believe the icon is stretched - and not simply a bigger (hdpi) image file - because it's slightly blurred) and either obscure or crowd out the title text, so all I see is the oversized, blurry icon. Of course, I also tried copying the icon from the drawable-mdpi folder: using the mdpi icon doesn't obscure the title, but the icon is slighlty undersized and blurry.

我想一个截图,所以我切换到我的模拟器中运行的应用程序。然而,模糊不明显,和当地MDPI形象似乎符合内部的那个我引用:

I wanted a screenshot, so I switched to running the app on my emulator. However, the blurring isn't apparent, and the local mdpi image seems to match the internal one I'm referencing:

[画面] (适用于跟随顶部的链接!)

[screenshot] (follow the link at the top!)

我有双重检查:),它真的是模糊我的手机(摩托罗拉Droid)。在

I have double-checked :), and it really is blurred on my phone (Motorola Droid).

这也发生在我所引用的人们可能会得到通过一个XML文件(如国家列表绘制)的图标,XML文件以某种方式定义的图像是如何被绘制。我试图使一个具有位图元素,并尝试设置几个属性的方面,我想可能有帮助:

It also occurred to me that the referenced one might be getting the icon via an xml file (like a state-list drawable), and that the xml file somehow defined how the image was to be drawn. I tried making one with a bitmap element, and tried setting a couple of the properties in ways I thought might help:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
 android:src="@drawable/ic_menu_close_clear_cancel"
 android:gravity="top"
 android:filter="false" />

它的工作要显示的图标(我为自己感到骄傲),但并没有影响拉伸的问题。

It worked to display the icon (I was proud of myself), but didn't affect the stretching issue.

我还发现这些的 [LINK4和link5] 页,但他们似乎有不同的问题。

I also found these [link4 and link5] pages, but they seemed to have different issues.

也许我应该抄袭其他位置的图标?我在正确的轨道与xml文件吗?帮助?

Perhaps I should be copying the icons from another location? Am I on the right track with the xml file? Help?

谢谢,

诺兰

推荐答案

如果你想拥有的图标在所有屏幕密度正常显示,那么你应该创建自己的绘制,MDPI,绘制,华电国际等文件夹和复制图标到每个那些。

If you want to have the icon appear correctly in all screen densities, then you should create your own drawable-mdpi, drawable-hdpi, etc folders and copy the icons into each of those.

这种方式正确大小的图标将被用于每个密度。有关如何工作的更多详细信息,请参阅支持多种屏幕尺寸,特别是部分资源预选赛。

That way the correct size icon will be used for each density. For more details on how this works, see supporting multiple screen sizes, particularly the section on resource qualifiers.

这篇关于在Android的选项菜单舒展本地图标填写菜单项,晦涩题名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆