0

How to show border on TextInputLayout in Android without MaterialComponents.

I have an AppCompatActivity using AppTheme.DialogTheme to show the Activity as a Dialog, but this configuration does not support MaterialComponents. When I use:

style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox

The App Builds successfully but generates a runtime error:

Error inflating class com.google.android.material.textfield.TextInputLayout

This is the XML layout using the MaterialComponent:

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/inputLayout"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="20dp"
        android:layout_marginVertical="20dp"
        android:layout_marginTop="10dp"
        app:helperTextEnabled="true"
        app:helperTextTextColor="@color/red">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/newfolder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Enter New Folder"
            android:imeOptions="actionNext"
            android:inputType="text"
            android:maxLength="32"
            android:scrollIndicators="bottom"
            android:scrollbars="horizontal"
            android:scrollHorizontally="true" />
    </com.google.android.material.textfield.TextInputLayout>

1 Answer 1

0

I found one way to add a border to the TextInputLayout without MaterialComponents.

I added a Shape to the Drawables.

switch_border.xml file:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
    <stroke
        android:width="2dp"
        android:color="@color/black"/>
</shape>

Then added to the TextInputLayout:

android:background="@drawable/switch_border"

Not the answer you're looking for? Browse other questions tagged or ask your own question.