【问题标题】:Change style of the right icon error TextInputLayout更改右侧图标样式错误TextInputLayout
【发布时间】:2016-10-24 18:22:13
【问题描述】:

我想更改 TextInputLayout 中右侧图标错误(带有 ! 符号的图像)的样式,但我不知道怎么做。

有可能吗?

【问题讨论】:

  • 你能提供你现在使用的代码吗。看起来你在edittext上设置错误。

标签: android android-textinputlayout material-components material-components-android


【解决方案1】:

使用材料组件库只需使用 app:errorIconDrawable 属性。

类似:

<com.google.android.material.textfield.TextInputLayout
    app:errorIconDrawable="@drawable/..."
    ../>

【讨论】:

    【解决方案2】:

    要在您的 Java 类中执行此操作,您可以执行以下操作:

    // initialize your drawable object
    Drawable myErrorDrawable = getResources().getDrawable(R.drawable.my_error_drawable);
    
    // set the dimension/bounds
    myErrorDrawable.setBounds(0, 0, myErrorDrawable.getIntrinsicWidth(), myErrorDrawable.getIntrinsicHeight());
    
    // attach the drawable to your EditText.
    editText.setError("An error occured", myErrorDrawable);
    

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2015-11-19
      • 2020-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      相关资源
      最近更新 更多