如何在TextInputLayout内部更改edittext的边框颜色

时间:2020-09-25 05:57:29

标签: android android-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时出现问题。我该如何解决?

2 个答案:

答案 0 :(得分:1)

在可绘制文件夹中创建可绘制文件,即 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>

并将此可绘制对象设置为edittext

 drawble = "@drawable/drawble_name"
 

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

答案 1 :(得分:1)

按照您的风格放置样式,

<style name="LoginTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
    <item name="boxStrokeColor">#fff</item>
    <item name="boxStrokeWidth">2dp</item>
</style>

并将以下颜色添加到您的color.xml

<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#fff</color>

What is sjavac, who is it for and how do I use it?

相关问题