Reputation: 635
I am using android TextInputLayout to show floating label on EditText.
But i want to show a ProgressBar on left of EditText thus i have added a relative layout inside the TextInputLayout and EditText inside that Relative Layout.
by doing so,The floating label does not work.
If i remove in the relative layout from the TextInputLayout and make the EditText direct children of it,Then it Works.
So does EditTExt needs to be a direct children of TextInputLayout and if so,how can we put another widget to EditTexts left like ProgressBar.
As TextInputLayout inhertis from LinearLayout,adding children to it will add children vertically but i want to add views on top of EditText.
<android.support.design.widget.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/holderName"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/etField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
>
</android.support.design.widget.TextInputEditText>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyle"
android:layout_width="16dp"
android:layout_height="match_parent"
android:indeterminateTint="@color/primary"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="15dp"
android:visibility="visible"
/>
</FrameLayout>
Upvotes: 0
Views: 1037
Reputation: 123
Solution is to wrap the TextInputLayout
and ProgressBar
with FrameLayout
like this:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="@+id/holderName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<android.support.design.widget.TextInputEditText
android:id="@+id/etField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name" />
</android.support.design.widget.TextInputLayout>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyle"
android:layout_width="16dp"
android:layout_height="match_parent"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="15dp"
android:indeterminateTint="@color/primary"
android:visibility="visible" />
</FrameLayout>
Upvotes: 2
Reputation: 2770
That functionality is not available. In addView()
it directly searches for the EditText
.
Here is the code
@Override
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);
} else {
// Carry on adding the View...
super.addView(child, index, params);
}
}
So, the first child must be of type EditText
.
If you want that functionality then inside RelativeLayout
take your TextInputLayout
and the ProgressBar
and set the positions of Progressbar
Upvotes: 0