Setting app level theme for TextInputLayout

If you have same design across app for TextInputLayout you can set app level style for TextInputLayout inside TextInputLayout you can set different properties to theme for TextInputLayout below is the example from material design theme.

you can change parent for TextInputLayout from FilledBox to OutlinedBox and other styles can use different properties to customize the design. there is list of properties you can explore on material design website.

If you have to different style for some places for TextInputLayout you can always set custom style at layout level xml which will override the app level theme.

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="textInputStyle">@style/Widget.App.TextInputLayout</item>
</style>

<style name="Widget.App.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.TextInputLayout</item>
<item name="shapeAppearance">@style/ShapeAppearance.App.SmallComponent</item>
<item name="hintTextColor">?attr/colorOnSurface</item>
<item name="boxBackgroundColor">@android:color/background_dark</item>
</style>

<style name="ThemeOverlay.App.TextInputLayout" parent="">
<item name="colorPrimary">@android:color/holo_red_light</item>
<item name="colorOnSurface">@android:color/holo_red_light</item>
<item name="colorError">@android:color/holo_blue_dark</item>
<item name="textAppearanceSubtitle1">@style/TextAppearance.App.Subtitle1</item>
<item name="textAppearanceCaption">@style/TextAppearance.App.Caption</item>
<item name="editTextStyle">@style/Widget.MaterialComponents.TextInputLayout.FilledBox</item>
</style>

<style name="TextAppearance.App.Subtitle1" parent="TextAppearance.MaterialComponents.Subtitle1">

</style>

<style name="TextAppearance.App.Caption" parent="TextAppearance.MaterialComponents.Caption">

</style>

<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">4dp</item>
</style>
</resources>




Comments

Popular posts from this blog

Using TabLayout and ViewPager with CollapsingToolbarLayout

Using android BadgeDrawable to show the Badge android

styling android TabLayout material design