开发者

Access Widget Attribute Through AttributeSet - Android

This should be fairly simple task. I have a view with the following:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:panel="org.miscwidgets"

<org.miscwidgets.widget.Panel
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="right"
    panel:handle="@+id/panelHandle"
    panel:content="@+id/panelContent"
   开发者_如何学JAVA panel:position="right">

I am attempting to access the position property in the constructor of the view, however it consistently returns null.

        String posVal = attrs.getAttributeValue("schemas.android.com/apk/gen/org.miscwidgets", "position");

How can I get the value? Is my namespace wrong?

I've seen references to Styleables but I've been unsuccessful in finding any that were not deprecated.


I think you should write in your xml

xmlns:panel="http://schemas.android.com/apk/gen/org.miscwidgets"

Instead of

xmlns:panel="org.miscwidgets"

And get it by

attrs.getAttributeValue("http://schemas.android.com/apk/gen/org.miscwidgets", "position");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜