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.

Broken TextInputLayout with support library 24.2.0

See original GitHub issue

Android support library 24.2.0 introduced these changes to TextInputLayout:

     public TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
          ...
+        mInputFrame = new FrameLayout(context);
+        mInputFrame.setAddStatesFromChildren(true);
+        addView(mInputFrame);
          ...
     }
     ...
     public void addView(View child, int index, final ViewGroup.LayoutParams params) {
         if (child instanceof EditText) {
+            mInputFrame.addView(child, new FrameLayout.LayoutParams(params));
+
+            // Now use the EditText's LayoutParams as our own and update them to make enough space
+            // for the label
+            mInputFrame.setLayoutParams(params);
+            updateInputLayoutMargins();
+
             setEditText((EditText) child);
-            super.addView(child, 0, updateEditTextMargin(params));
         } else {
         ...

Anvil’s rendering breaks TextInputLayout as it always tries to replace FrameLayout inside with EditText. I really like Anvil’s reactive views approach, however, I’d like to also use latest stable support library. Any suggestions how to overcome this? Thank you.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:8

github_iconTop GitHub Comments

1reaction
zsergecommented, Feb 26, 2017

Well, this is a bugger. I don’t see how Anvil can nicely handle this. Support Library developers have broken too many things here - they’re injecting views, in the unexpected order, and they’ve overridden addView() behavior, mess with LayoutParams, and to make it even worse - they’ve overridden one particular addView() implementation with one particular use case (XMLs).

Still, Anvil is a cool little library that allows to work this around (even with no xmls):

            textInputLayout(() -> {
                size(FILL, WRAP);
                init(() -> {
                    ViewGroup layout = Anvil.currentView();
                    TextInputEditText editText = new TextInputEditText(getContext());
                    editText.setId(123);
                    layout.addView(editText, layout.getChildCount(),
                            new LinearLayout.LayoutParams(FILL, WRAP));
                });
                withId(123, () -> {
                    size(FILL, WRAP);
                    textSize(sip(24));
                });
                hint("Some hint");
                skip();
            });

Here I’m creating a child view directly using its constructor. Then I assign some ID to it (it may not be unique, but it should be unique within the TextInputLayout). Then I find that edit text view by ID, set the rest of its attributes as one would normally do with Anvil, finally, I skip all the child views that were not created by Anvil. This brings the expected results.

However, I have to agree, that if the view is designed to be used exclusively from XML - there is no reason to make it even more painful. I would agree with the suggestion to use an XML layout for this view hierarchy specifically.

By the way, there is a good chance that existing XML-related issues are all gone, you may check the most recent marser branch - I’ve rewritten too much to describe it here, but you may look at #99 for a bigger picture.

1reaction
defHLTcommented, Nov 10, 2016

@jakubkulhan Did you check if xml and withId will make any difference?

xml(R.layout.textinputlayout_with_edittext) {
    //...

    withId(R.id.edit_text) {
        //...
    }

  //...

}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Broken TextInputLayout with support library 24.2.0 · Issue #81 · anvil ...
Broken TextInputLayout with support library 24.2.0 #81 ... Anvil's rendering breaks TextInputLayout as it always tries to replace FrameLayout inside with ...
Read more >
TextInputLayout not showing hint in IME extract mode, on 24.2 ...
After upgrading to support library 24.2.0 TextInputEditText stopped showing hints in IME extract mode ( works fine on 24.1.0 ). Library used (support-v4, ......
Read more >
Support Library Revision Archive - Android Developers
This page provides details about older Support Library package releases. ... Note: Release 24.2.0 removes support for Android 2.2 (API level ...
Read more >
Android TextInputLayout Password toggle not visible in new ...
The TextInputLayout password toggle is now disabled by default to avoid unnecessarily overwriting developer-specified end drawables.
Read more >
Android Support Library v24.2 released : r/androiddev - Reddit
EDIT 3: As much as I greatly appreciate breaking up support-v4 into smaller ... Found a bug in design library 24.2.0, notice the...
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