Tag Archives: android:name

Activity Layout Fragment attribute class: vs android:name

In case you wonder whether to use:

<fragment class="myapp.MyFragment" ..


<fragment android:name="myapp.MyFragment" ..

Well it doesn’t really matter. You can use both.

Lets see why in Activity.onCreateView source:

String fname = attrs.getAttributeValue(null, "class");
TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment);
if (fname == null) {
    fname = a.getString(com.android.internal.R.styleable.Fragment_name);

So it seems it first checks for ‘class’ and if not there then for ‘android:name’.