你如何获得"机器人:"在自定义视图标签值 [英] How do you get "android:" tag values in a Custom View
问题描述
似乎有很多的相似的问题和答案,这样分散在各地,所有指如何从一个的AttributeSet
自定义属性。我一直没能找到到目前为止是如何获得机器人:
命名空间标记:
There seems to be alot of "similar" questions and answers to this scattered around which all refer to how to get a custom attribute from an AttributeSet
. What I haven't been able to find so far is how to get an android:
namespace tag:
<com.custom.view.StatusThumbnail
android:id="@+id/statusThumbnailContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"/>
我想拉回 layout_height
属性,从这个自定义组件。不幸的是,从我读过的最接近我得如何做到这一点的是:
I would like to pull back the layout_height
attribute from this custom component. Unfortunately from what I've read the closest I've got to how to do this is:
public StatusThumbnail(Context context, AttributeSet attrs) {
super(context, attrs);
String height = attrs.getAttributeValue("android", "layout_height");
但是,这将返回空
。
当然,这并不是罕见的事情,试图做?
Surely this isn't a rare thing to try and do?
推荐答案
命名空间应该是 http://schemas.android.com/apk/res/android
Android是在XML文件中声明的别名
The namespace should be "http://schemas.android.com/apk/res/android
" android is an alias declared in your xml file
这篇关于你如何获得&QUOT;机器人:&QUOT;在自定义视图标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!