为我在 XML (Android) 中制作的按钮设置图片?
我有一个关于在 XML 中设置按钮图片的问题:
我制作了一些 .png 图片,我想将其设置为图片,而不是创建 Android 应用程序时默认获得的按钮。现在我将文件加载到可绘制文件夹.. 我该如何编写 XML 以获得正确的内容?
是否可以将按钮可见设置为 false 并添加图片作为其背景? 因为这就是我思考的所有方式。或者有更好的方法来做这种事情吗?
I'm having this question about setting pictures for Buttons in XML :
I made some .png pictures I want to set as pictures instead of the buttons that I get in default when i create my android apps.. Now I loaded in the files into the drawable folder.. And how do I write in XML to get the right thing?
Is setting the button visible to false and adding a picture as background for it an option?
Because that's all the ways I thought about. Or is there a better way to do this kind of thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的理解是你想将图片设置为背景。在您的 Button 标签中这样做:
what I understood is that you want to set the picture in background. Do it like this in your Button tag:
将 png 添加到项目中 res 文件夹下的 drawable 文件夹中(如果您使用的是 eclipse)。然后在您的 XML 文件中只需使用
android:background="@drawable/filename"
。确保省略文件扩展名Add the png to the drawable folder that is under the res folder in your project (if you are using eclipse). Then in your XML file simply use
android:background="@drawable/filename"
. Make sure to omit the file extension您可以使用以下任意一个:
drawableTop、drawableLeft、drawableRight、drawableBottom
例如,
在本例中,图像 some_image.png 将位于文本的右侧。
You can use any of:
drawableTop, drawableLeft, drawableRight, drawableBottom
For example,
The image some_image.png will be positioned to the right of your text in this case.