Custom xml attributes without attrs.xml file

Dimon_Ripper

New Member
Recently I've faced with adding custom xml parameters to my views in xml layout. I know that I should use attrs.xml file for this purpose, but... I have found, that I can use custom parameters without any attrs.xml file at all. Can somebody explain this ? Is this a bug or is this a valid case ?here is my custom view:\[code\]public class TestView extends View {public TestView(final Context context, final AttributeSet attrs) { this(context, attrs, 0);}public TestView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final String scheme = "http://red.com/ui/scheme"; if (attrs != null) { Log.d("TestView", "custom param value: " + attrs.getAttributeValue(scheme, "cutom")); }}\[/code\]}and here is the main layout:\[code\]<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:red="http://red.com/ui/scheme"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /><com.red.ui.TestView android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#ffAABBCC" red:cutom="customvalue" /> </LinearLayout>\[/code\]It is a simple scratch project, created by Android wizard.
 
Back
Top