为我在 XML (Android) 中制作的按钮设置图片?

发布于 2024-12-04 19:02:14 字数 199 浏览 2 评论 0原文

我有一个关于在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瀟灑尐姊 2024-12-11 19:02:14

我的理解是你想将图片设置为背景。在您的 Button 标签中这样做:

android:background="@drawable/yourpicturename"

what I understood is that you want to set the picture in background. Do it like this in your Button tag:

android:background="@drawable/yourpicturename"
看轻我的陪伴 2024-12-11 19:02:14

将 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

遮了一弯 2024-12-11 19:02:14

您可以使用以下任意一个:

drawableTop、drawableLeft、drawableRight、drawableBottom

例如,

<Button android:drawableRight="@drawable/some_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Some text" />

在本例中,图像 some_image.png 将位于文本的右侧。

You can use any of:

drawableTop, drawableLeft, drawableRight, drawableBottom

For example,

<Button android:drawableRight="@drawable/some_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Some text" />

The image some_image.png will be positioned to the right of your text in this case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文