material-components / material-components/material-components-android

[TextInputLayout] Setting end icon gravity

Open
#2,777 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request Widget: TextField
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

In a multi line TextInputEditText the end icon is always centered, but in some cases we need it to be set to top or at the bottom of the layout.
![Screenshot from 2022-06-25 11-20-13](https://user-images.githubusercontent.com/26392026/175767013-2247001f-d16c-4049-a233-dce1b5418f3f.png)

After some internet research I didn't find any suitable solution. I tried to explore the implementation class TextInputLayout.java and found out that the end icon is place as a drawable in CheckableImageButton (com.google.android.material.R.id.text_input_end_icon) and the button is place in a FrameLayout.

What I did is finding the button by its ID and then customize the layout params.

```java
// using viewbinding
private ActivityCommentBinding mBinding;

// change the end icon gravity
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mBinding.commentTextLayout
.findViewById(com.google.android.material.R.id.text_input_end_icon)
.getLayoutParams();
params.gravity = Gravity.TOP;
mBinding.commentTextLayout
.findViewById(com.google.android.material.R.id.text_input_end_icon)
.setLayoutParams(params);

```
Result:

![Screenshot from 2022-06-25 11-33-40](https://user-images.githubusercontent.com/26392026/175767664-e3d1a23b-0f54-48f8-b45c-26319ef06e7a.png)

**Describe the solution you'd like**
I think it would be useful to have a TextInputLayout XML attribute to set the end icon gravity.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading TextInputLayout.java and the CheckableImageButton identified in the issue to understand how the end icon is positioned. Define the public XML attribute and its supported gravity values, then verify that multiline end icons can be aligned at the top or bottom while preserving existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
design, mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.