How to set TextInputLayout error message colour?

前端 未结 9 2221
旧巷少年郎
旧巷少年郎 2020-11-27 13:58

How can I change the colour of the error message that can be set to appear below the text field in a TextInputLayout (via setError(...) – see error

9条回答
  •  没有蜡笔的小新
    2020-11-27 14:39

    Depending on need, one can change/set TextInputLayout text color dynamically or directly in the layout XML file. Below is sample code snippets

    Create a custom style which uses @android:style/TextAppearance as parent in your styles.xml file:

    
    

    And, use it in your TextInputLayout widget:

    1. Directly in XML Layout
     
    
    1. Dynamically in your class
    your_input_layout.setErrorTextAppearance(R.style.style_error_appearance);
    

    If you want to set single/same error text color for your application then define the text color in your app theme

    
    

    And in your AndroidManifest.xml:

    
    
        
    
    
    

提交回复
热议问题