Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout passwordToggle with rounded corners

I'm using TextInputLayout from android design library version 25.1.1. With the following code:

<android.support.design.widget.TextInputLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:local="http://schemas.android.com/apk/res-auto"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  local:passwordToggleEnabled="true"
  local:hintEnabled="false">
  <android.support.design.widget.TextInputEditText
    android:id="@+id/confirmationEditText"
    android:singleLine="true" />
</android.support.design.widget.TextInputLayout>

But when password toggle icon is pressed, its ripple effect is drawn above the background of TextInput: Background pressed state

How can I set rounded corners radius for passwordToggle? Can I reference its existing background and "wrap" it with needed properties (how to find Path for default drawable that is used by toggle)?

like image 462
Sly Avatar asked Mar 06 '17 09:03

Sly


People also ask

How do I set TextInputLayout style programmatically?

Method 1 - Create TextInputLayout programmatically with wrapping Context with android. view. ContextThemeWrapper and use. TextInputLayout layout = new TextInputLayout(new ContextThemeWrapper(getContext(), R.

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 Textinput layout?

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.

How do I change the color of my TextInputLayout line?

You can apply a custom style to change the colors. 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

Just use the Material Components library and the standard TextInputLayout component.

Add the app:boxCornerRadiusBottomEnd="xxdp", app:boxCornerRadiusTopEnd="xxdp", app:boxCornerRadiusBottomStart="xxdp", app:boxCornerRadiusTopStart="xxdp" attributes.

Something like:

    <com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        app:endIconMode="password_toggle"
        app:boxCornerRadiusBottomEnd="8dp"
        app:boxCornerRadiusTopEnd="8dp"
        app:boxCornerRadiusBottomStart="8dp"
        app:boxCornerRadiusTopStart="8dp"
        ...>

enter image description here

Otherwise you can define a custom style and use the shapeAppearanceOverlay attribute:

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/custom_end_icon"
        android:hint="Hint text"
        style="@style/OutlinedRoundedBox"
        ...>

with:

  <style name="OutlinedRoundedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    <item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded</item>
  </style>

  <style name="ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">8dp</item>
  </style>
like image 88
Gabriele Mariotti Avatar answered Sep 24 '22 11:09

Gabriele Mariotti