Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering problems using new TextInputLayout for EditText

Tags:

android

I'm trying to set the new support.desing library that provides some lollipop visual effects to old android versions.

In this case, I'm triying to add the floating labels for the edittext, which is done with the widget.TextInputLayout:

enter image description here

To do this I have followed google's provided few indications:

  • I have downloaded the last support library (22.2.0) and included on graddle file.

    compile 'com.android.support:design:22.2.0'

  • I have added the TextInputLayout in my xml this way:

<android.support.design.widget.TextInputLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:layout_marginLeft="20dp">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="12"
        android:hint="hint"
        android:inputType="number"
        android:id="@+id/edt" />
</android.support.design.widget.TextInputLayout>

But Android Studio is showing this in the layout preview:

Rendering failed with a known bug. Please try a rebuild.  
The following classes could not be instantiated:
- android.support.design.widget.TextInputLayout (Open Class, Show Exception, Clear Cache)

Exception Details 
java.lang.NoSuchFieldError: TextAppearance

This is the style I'm using:

<style name="MaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/md_red_500</item>
    <item name="colorPrimaryDark">@color/darkPrimaryColor</item>
    <item name="colorAccent">@color/md_green_500</item>
    <item name="android:textColorPrimary">@color/md_grey_900</item>
    <item name="android:textColorSecondary">@color/md_grey_600</item>
</style>

EDIT-

enter image description here

like image 299
masmic Avatar asked Jun 01 '15 10:06

masmic


People also ask

How do I get TextInputLayout from text?

TextInputLayout textInputCustomEndIcon = findViewById(R. id. editText); final TextInputEditText editText = new TextInputEditText(textInputCustomEndIcon. getContext()); textInputCustomEndIcon.

How do I change the color of my TextInputLayout line?

To change the hint color you have to use these attributes: hintTextColor and android:textColorHint . To change the bottom line color you have to use the attribute: boxStrokeColor .


1 Answers

Solved. Had to add this:

<android.support.design.widget.TextInputLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:layout_marginLeft="20dp"
            app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">

Where this just is:

<style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/accentColor</item>
</style>
like image 75
masmic Avatar answered Oct 02 '22 17:10

masmic