膨胀期进入按钮? [英] Inflating a view into Button?

查看:167
本文介绍了膨胀期进入按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个问题的一些论坛和未想知道如果任何人有关于如何回答一个线索。

I saw this questions unanswered on some forums and wonder if anyone have a clue on how to answer.

比方说,比如需要用图片和文字的按钮。这似乎自然地创建一个XML视图,然后将其扩充到按钮。这可能吗?

Let's say for instance a button is needed with a picture and a text. It would seem natural to create an xml view and then inflate it into the Button. Is this possible?

目前,我不需要按钮,看点击或改变它在点击的颜色,但它也可能是有趣的考虑这将如何通过使充气受到影响。

At the moment I don't need the button to look clickable or change it's color at click, but it could also be interesting to consider how this will be affected by making the inflate.

顺便说一句,我发现这个教程中描述的解决同样的问题,但他们写扩展视图,以获得目标的类。这似乎有点overklill给我。
http://kahdev.word$p$pss.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/

Btw, I found this one tutorial describing a solution to the same problem, but they were writing a class extending View to obtain the goal. That seems a bit overklill to me. http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/

在此先感谢!
安娜

Thanks in advance! Anna

推荐答案

请您的自定义按钮的XML布局,包含的TextView和ImageView的。将下面的属性到根布局文件:

Make a XML layout of your custom Button, that contains the TextView and ImageView. Put the following attributes to the root layout in the file:

android:background="@android:drawable/btn_default"
android:focusable="true"
android:clickable="true"

,你会得到你所需要的。

and you'll get what you need.

这篇关于膨胀期进入按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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