last day (15 days later) » 

10:48 AM
0
A: How Can I set style to TextInputLayout by dynamically in android?

Gabriele MariottiThe 2nd parameter of the ContextThemeWrapper is a theme overlay, not a style. You can define in attrs.xml a custom attribute: <attr name="customTextInputStyle" format="reference" /> then in your app theme: <style name="AppTheme" parent="Theme.MaterialComponents.DayNight"> <item name="customT...

 
Neo
it is not working :( I create an attrs.xml file in values and add your code block . after I add your style code into styles folder . I had to change name of the style . But my problem still continue :(
I did the same answer you shared, what could I have done wrong?
 
@Neo The name of the theme is not a problem, just use your theme adding the customTextInputStyle attribute. Are you using a material components theme? Are you using the 1.3.0 ?
 
Neo
I am using 1.1.0
 
Try to update to 1.3.0
 
Neo
When I update the version of the material, my problem persists and the TextInputlayouts that I created before were broken.
 
10:48 AM
@Neo just tried in a new empty project and it works. Try to use it in an empty project, and post your app theme. If the previous TextInputlayouts are broken there is something wrong in your projetct.
 
Neo
 <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppBaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
        <item name="android:windowBackground">@color/Thistle</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
that is my styles file
and I also add the style file  <style name="ThemeOverlay.AppTheme.TextInputEditText.Outlined" parent="">
        <item name="colorPrimary">@color/white</item>
        <item name="boxCornerRadiusBottomEnd">20dp</item>
        <item name="boxCornerRadiusBottomStart">20dp</item>
        <item name="boxCornerRadiusTopEnd">20dp</item>
        <item name="boxCornerRadiusTopStart">20dp</item>
        <item name="android:hint">Number of player</item>
        <item name="hintTextColor">@color/card1</item>
that is my build.gradle
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    implementation 'com.google.android.material:material:1.1.0'
    implementation 'com.github.f0ris.sweetalert:library:1.5.6'
 
Just tried with 1.3.0 and Theme.MaterialComponents.Light.NoActionBar.Bridge with the code posted in the answer and it works.
 
Neo
Would you see if I post my project on github?
 
About the other textinputlayout. If you are using a bridge theme you have to add <item name="textInputStyle">@style/Widget.MaterialComponents.TextInputLayout.FilledBox</item> in the app theme.
Just try to create an empty new project with 1.3.0 and try them.
 
Neo
11:03 AM
I am trying
Creates a TextInputLayout, but not in the style I want. It shapes it the way it created in the other project.
 
what did you add in the style? Did you read my previous comment?
 
Neo
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Control" parent="Theme.MaterialComponents.DayNight">
<item name="customTextInputStyle">@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item>
</style>
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'com.google.android.material:material:1.3.0'

}
 
Neo
where is the mistake
 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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.MaterialComponents.TextInputLayout.FilledBox</item>
<item name="customTextInputStyle">@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item>
</style>
and your Activity has to use the AppTheme theme.
No sorry
You can't use a AppCompat theme
 
Neo
11:11 AM
I'm confused
 
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- Customize your theme here. -->
<item name="textInputStyle">@style/Widget.MaterialComponents.TextInputLayout.FilledBox</item>
<item name="customTextInputStyle">@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item>
It is your AppTheme + textInputStyle +customTextInputStyle.
In this way works both, TIL created programatically and with layout.
 
Neo
it is working correctly thank u
It also works on 1.1.0 version.
When I change the version, the text input layout I created before is distorted :(
can i ask you one more thing ?
 
Neo
11:37 AM
how can I change that TextInputlayout boxStrokeColor, hintTextColor, Cursor Color etc. I use for til.setBoxStrokeColor = (getResources().getColor(R.color.selector ))(stackoverflow.com/questions/67020226/…) to change boxStrokecolor but boxStroke color change when I click it.
 
11:48 AM
Use til.setBoxStrokeColor = ContextCompat.getColorStateList(this,R.color.selector). the getColor() method doesn't use a selector.
if this answer has solved your question please consider accepting it by clicking the check-mark. There is no obligation to do this.
 
Neo
til.setBoxStrokeColor(ContextCompat.getColorStateList(this,R.color.selector)); that code is not working / error: incompatible types: ColorStateList cannot be converted to int
 
Neo
12:14 PM
I will click the check - mark, dont worry
 
12:43 PM
Use til.setBoxStrokeColorStateList() method
 
Neo
There is no such method as til.setBoxStrokeColorStateList ().
 
 
1 hour later…
1:59 PM
You have to update the library to 1.2.0, at least.
 

last day (15 days later) »