Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is always a default background on TextInputLayout in Android

Tags:

I have TextInputLayout and TextInputEditText like this

<com.google.android.material.textfield.TextInputLayout             android:id="@+id/loginUsernameText"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_marginLeft="@dimen/text_input_margin_left_right"             android:layout_marginRight="@dimen/text_input_margin_left_right"             android:layout_marginTop="@dimen/text_input_margin_top_bottom"             android:hint="@string/username"             android:layout_below="@id/loginButtonLogin">          <com.google.android.material.textfield.TextInputEditText                 android:id="@+id/loginUsername"                 android:layout_width="match_parent"                 android:padding="5dp"                 android:layout_height="wrap_content"                 android:inputType="textEmailAddress"/>      </com.google.android.material.textfield.TextInputLayout>      <com.google.android.material.textfield.TextInputLayout             android:id="@+id/loginPasswordText"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_marginLeft="@dimen/text_input_margin_left_right"             android:layout_marginRight="@dimen/text_input_margin_left_right"             android:layout_marginTop="@dimen/text_input_margin_top_bottom"             android:hint="@string/password"             android:layout_below="@id/loginUsernameText">          <com.google.android.material.textfield.TextInputEditText                 android:id="@+id/loginPassword"                 android:layout_width="match_parent"                 android:padding="5dp"                 android:layout_height="wrap_content"                 android:inputType="textPassword"/>      </com.google.android.material.textfield.TextInputLayout> 

This is my styles.xml file

<resources>      <!-- Base application theme. -->     <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">         <!-- Customize your theme here. -->         <item name="colorPrimary">@color/colorPrimary</item>         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>         <item name="colorAccent">@color/colorAccent</item>     </style>      <style name="AppTheme.NoActionBar">         <item name="windowActionBar">false</item>         <item name="windowNoTitle">true</item>     </style>      <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />     <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />      <style name="TextAppearance.App.TextInputLayout" parent="@android:style/TextAppearance">         <item name="android:textColor">@color/white</item>         <item name="android:textSize">14sp</item>     </style>  </resources> 

So I am not using anything extra on TextInputLayout and they are appearing like this enter image description here

This grey background is always there. How do I remove this background and just get the default TextInputLayout. Thanks.

like image 564
theanilpaudel Avatar asked May 15 '19 03:05

theanilpaudel


People also ask

How do I remove the default padding in TextInputLayout?

You can just set the start and end padding on the inner EditText to 0dp. Here's a screenshot with Show Layout Bounds turned on so you can see that the hints go all the way to the edge of the view.

What is TextInputLayout Android?

TextInputLayout is a view container that is used to add more features to an EditText. It acts as a wrapper for EditText and has some features like: Floating hint. Animation that can be disabled or enabled. Error labels that display error messages when an error occurs.

What is textinputlayout in Android?

TextInputLayout ​​​​​​​is an interface component that contains and supports a Text Input Field visually. If EditText is in use, make sure its android:background is @null so that TextInputLayout can set the appropriate background for it. The hint text automatically pops up when the user focus to EditText.

How to avoid unintended behavior when using textinputlayout on edittext?

To avoid unintended behavior, call setHint (CharSequence) and getHint () on TextInputLayout, instead of on EditText. If the EditText child is not a TextInputEditText, make sure to set the EditText 's android:background to null when using an outlined or filled text field.

How to show plain-text password in textinputlayout?

The TextInputLayout will show a password toggle button if its EditText displays a password. When this end icon is clicked, the password is shown as plain-text if it was disguised, or vice-versa.

Can I change the color of the error in a textinputlayout?

Since it is not easy to customize the color of the error in a TextInputLayout, I decided to change my error colour to match the one used by default by TextInputLayout. In the design guidelines I could not find the definition of the default colour. Do you know where I can find it? The only solution I found was to check the code of TextInputLayout.


Video Answer


1 Answers

https://github.com/material-components/material-components-android/issues/102

It seems a material textfield bug.
You can use this code to change background white temporarily.

<com.google.android.material.textfield.TextInputLayout    app:boxBackgroundColor="@android:color/transparent"     android:background="@android:color/transparent">    <com.google.android.material.textfield.TextInputEditText/> </com.google.android.material.textfield.TextInputLayout> 
like image 165
Mina chen Avatar answered Sep 21 '22 20:09

Mina chen