Android ImageButton / 自定义按钮?
我是安卓开发新手。到目前为止,我可以通过阅读 stackoverflow 上的线程来帮助自己解决所有问题。现在我陷入困境,需要别人的帮助。不幸的是,我不被允许发布屏幕截图,因为我是新人,所以我尝试描述它。
我有一个三星 Galasy S,它附带的时钟应用程序有一个名为“+ 创建闹钟”的按钮。我想为我的应用程序创建一个类似的按钮。 我一直在尝试使用 ImageButton。我确实知道如何将“+”图标放到 ImageButton 上,但仅居中且没有文本。我猜这是一个自定义按钮。有谁知道该怎么做?我可以在 xml 中完成它还是需要扩展视图类并使其成为我自己的视图?
I am new to android development. So far I could help myself in all matters by reading threads here on stackoverflow. Now I am stuck and need someones help. Unfortunately I am not allowed to post an image of a screenshot because I am a new mamber, so I try to descripe it.
I have a Samsung Galasy S and the clock app that ships with it has an button called "+ Create alarm". I want to create a similar button for my app.
I've been experimenting with ImageButton. I do know how to get that "+"-Icon onto an ImageButton, but only centered and without text. I guess this is a custom button. Does anyone know how to do this? Can I do it in xml or do I need to extend the view-class and make it my own view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将来,如果您希望我们帮助您使某些东西看起来像其他东西,那么拥有图像会有所帮助。使用 DDMS 的屏幕截图功能来记录您想要的内容,并将图像包含在您的问题中。
常规
Button
可以通过android:drawableBottom
、android:drawableLeft
等属性在文本的任意一侧添加图像。In the future, if you want us to help you make something look like something else, it would help to have an image. Use the screenshot capability of DDMS to record what it is you want something to look like, and include the image in your question.
A regular
Button
can have an image to any side of the text, via theandroid:drawableBottom
,android:drawableLeft
, etc. attributes.您只能通过 xml 来完成此操作。有一个示例。您很可能已经做了类似的事情。但我的建议是创建您的自定义图像(您将在
ImageButton
上显示该图像),以便该图像包含您的图标和文本标签。然而看起来 CommonsWare 提出了一种更好的方法。You can do this via xml only. There's an example. Most likely you already do smth similar. But my advice is to create your custom image (which you will display on the
ImageButton
) so that image includes both your icon and the text label. However looks like CommonsWare proposes a better approach.