Skip to content

Instantly share code, notes, and snippets.

@kingargyle
Created May 31, 2016 17:08
Show Gist options
  • Save kingargyle/3b62f02f0e5c8f028499a41fc6d9c362 to your computer and use it in GitHub Desktop.
Save kingargyle/3b62f02f0e5c8f028499a41fc6d9c362 to your computer and use it in GitHub Desktop.
A bare bones Shadow for Robolectric and TextInputLayout from the design library
import android.support.design.widget.TextInputLayout;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.shadows.ShadowViewGroup;
@Implements(TextInputLayout.class)
public class ShadowTextInputLayout extends ShadowViewGroup {
@RealObject private TextInputLayout realTextInputLayout;
}
@kingargyle
Copy link
Author

User this by adding:

@config( constants = BuildConfig, shadows = { ShadowTextInputLayout.class })

To the test classes that need the ShadowTextInputLayout

@jpaseneta
Copy link

jpaseneta commented Jul 21, 2016

hi,

i've followed your instructions how to use this, but my inflating my layout.xml that has a TextInputLayout still throws

android.view.InflateException: XML file build/intermediates/res/merged/debug/layout/login_layout.xml line #-1 (sorry, not yet implemented): XML file build/intermediates/res/merged/debug/layout/login_layout.xml line #-1 (sorry, not yet implemented): Error inflating class android.support.design.widget.TextInputLayout

when running robolectric

Where should i save the shadow class? i've put it under my com.example.(test) folder.

@jpaseneta
Copy link

here is my login_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/login_linearlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <AutoCompleteTextView
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Email"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:singleLine="true" />

    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Password"
            android:inputType="textPassword"
            android:maxLines="1"
            android:singleLine="true" />

    </android.support.design.widget.TextInputLayout>

    <Button
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_gravity="center_horizontal"
        android:text="Login"
        android:textStyle="bold" />

</LinearLayout>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment