首页 > 解决方案 > 如何更改TextInputLayout内edittext的边框颜色

问题描述

我在edittext周围使用TextInputLayout。我想更改 TextInputLayout 中存在的编辑文本的边框颜色。

xml

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.design.widget.TextInputEditText
            android:id="@+id/Test1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </android.support.design.widget.TextInputLayout>

夏普

    private TextInputEditText editor;
    editor = FindViewById<TextInputEditText>(Resource.Id.Test6);
    editor.Background.SetColorFilter(Android.Graphics.Color.Red, Android.Graphics.PorterDuff.Mode.SrcAtop);

如果 TextInputLayout 中不存在编辑文本,则上述代码可以正常工作。只有在 TextInputLayout 中使用 edittext 时才会出现问题。我怎样才能解决这个问题?

标签: androidandroid-edittext

解决方案


在可绘制文件夹中创建可绘制文件,即drawable_name.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

  <!-- Background Color -->
  <solid android:color="#ffffff" />

  <!-- Border Color -->
  <stroke android:width="1dp" android:color="#e7e7e7e7" />

  <!-- Round Corners -->
  <corners android:radius="5dp" />

</shape>

并将这个drawable设置为edittext

 drawble = "@drawable/drawble_name"
 

根据您的要求更改边框颜色


推荐阅读