簡體   English   中英

如何更改 TextInputLayout 內編輯文本的邊框顏色

[英]How to change the border color of edittext inside the TextInputLayout

我在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 時才會出現問題。 我怎樣才能解決這個問題?

在可繪制文件夾中創建可繪制文件,即 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"
 

根據您的要求更改邊框的顏色

把風格放在你的風格里,

<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>

更改 TextInputLayout 輪廓顏色

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM