Reputation: 1512
I have textinputlayout and want to add an attribute to it but it work only when assigned from style
my style
<style name="round_text" parent="Base.Widget.MaterialComponents.TextInputLayout">
<item name="editTextStyle">@style/Widget.MaterialComponents.TextInputEditText.OutlinedBox</item>
</style>
my view with style
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input"
android:theme="?attr/textInputStyle"
style="@style/round_text"
android:layout_width="300dp"
android:layout_centerInParent="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
my view without style and attribute assigned directly
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input"
android:theme="?attr/textInputStyle"
android:editTextStyle="@style/Widget.MaterialComponents.TextInputEditText.OutlinedBox"
android:layout_width="300dp"
android:layout_centerInParent="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
Upvotes: 2
Views: 288
Reputation: 2254
There is no such thing as @style/Widget.MaterialComponents.TextInputEditText.OutlinedBox
.
There is, however, the @style/Widget.MaterialComponents.TextInputLayout.OutlinedBox
style for the TextInputLayout
.
The attribute you assigned directly was
TextInputEditText.OutlinedBox
. It should beTextInputLayout.OutlinedBox
Please Note that there is no
editTextStyle
. The reason it was being applied from yourstyle
is becauseround_text
had theparent="Base.Widget.MaterialComponents.TextInputLayout"
which by default uses theTextInputLayout.OutlinedBox
asstyle
.
According to the Material Design Docs, you should do the following:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input"
android:theme="?attr/textInputStyle"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="300dp"
android:layout_centerInParent="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
Upvotes: 1