question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[MaterialButton] Long button text gets cut off when using maxlines=2 and ellipsize=end

See original GitHub issue

Description: When using a MaterialButton with fixed width and fixed number of text lines, I tried to find a way to deal with dynamic button text that could be too long for the button size. When the text is too long for the button the words that don’t fit will simply not be displayed by default, thus not indicating that there are words missing. When setting “ellipsize” to “end” the three dots get displayed, but the beginning of the text will be cut off in some situations.

Steps to reproduce: Check out and run this sample project: https://github.com/geworfener/MaterialButtonEllipsizeBug

Alternatively:

  1. Create a new Android project with a single activity.
  2. Add material lib and set material theme.
  3. Use the following activity layout:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.button.MaterialButton
        android:layout_width="128dp"
        android:layout_height="wrap_content"
        android:maxLines="2"
        android:ellipsize="end"
        android:text="Hello world, this is a long text!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Actual behavior:

The first letter of the second text line gets cut off.

image

Expected behavior: All words of the text are displayed fully.

Android API version: 28

Material Library version: 1.1.0-beta02, 1.2.0-alpha02

Device: Pixel 3a XL

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
C0nstancommented, Sep 8, 2020

It still occurs in 1.2.0. This is a serios functionality bug, wherefore we cant use the MaterialButton in our project. Is there a time plan when this is getting fixed?

3reactions
gabrielemariotticommented, Aug 2, 2020

It happens also using android:maxLines="1":

    <com.google.android.material.button.MaterialButton
        android:layout_width="128dp"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:ellipsize="end"
        android:text="Hello world, this is a long text!"
         />
Schermata 2020-08-02 alle 19 45 05

It doesn’t happen with an AppCompatButton:

Schermata 2020-08-02 alle 19 45 59
Read more comments on GitHub >

github_iconTop Results From Across the Web

In android ellipsize text view between buttons - Stack Overflow
The problem is that when the text is long it also cuts the BEGINNING of the code (see image). I can fix that...
Read more >
Textview Gets Cut Off In Constraintlayout - ADocLib
[MaterialButton] Long button text gets cut off when using maxlines2 and ellipsizeend #841. Open. geworfener <androidx.constraintlayout.widget.
Read more >
MaterialButton - Android Developers
A convenience class for creating a new Material button. This class supplies updated Material styles for the button in the constructor.
Read more >
Textview ellipsize multiline not working (do not ... - Issue Tracker
When I use a text that is too long by exactly one character, the last word is correctly removed from the displayed text,...
Read more >
Diff - platform/frameworks/base - Google Git
KeyListener getKeyListener(); method public final android.text. ... BLE_ACL_DISCONNECTED"; + /** The profile is in disconnected state */ public static final ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found