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

[MaterialButton] Why Button rendering one more layer than TextView?

Open
#2,809 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Widget: Button
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Description:** Sorry, maybe it's not a bug, I just don't understand and couldn't find any clue to explain it.

I wrote a demo to illuminate it.

![overdraw](https://user-images.githubusercontent.com/24718357/178155708-4c6523c5-7aa2-4ba3-8583-c888fb0f9d21.png)

According to [Official Site](https://developer.android.com/topic/performance/rendering/inspect-gpu-rendering), here's the result.

| Top => Bottom | Behavior |
|:----:|:----:|
|`OutlinedButton` ( background = TRANSPARENT )| Blue - Overdrawn 1 time |
|`TextButton` ( background = TRANSPARENT )| Blue - Overdrawn 1 time |
|`TextView`| No overdraw |

So
* What causes this?
* Is there any way to avoid this overdraw?

**Source code:**
```

```

**Android API version:** compileSdk 31

**Material Library version:** `com.google.android.material:material:1.6.1`

**Device:** Google Pixel 3 - Android 12

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 reproducing the reported demo with Material Components 1.6.1 on Android 12/API 31, comparing the two MaterialButton styles with the TextView while GPU overdraw visualization is enabled. Review the supplied XML and determine what causes the extra layer and whether the transparent-background configuration can avoid it; done means documenting the cause and a supported workaround, if one exists.

Written by the indexing model from the issue text.

Assessment

Tech stack
android
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.