簡體   English   中英

TextInputLayout endIcon 背景色

[英]TextInputLayout endIcon background color

是否可以僅在 endIcon 后面使用背景顏色?

在此處輸入圖片說明

目前我所能做的只是顯示自定義圖標。

在此處輸入圖片說明

這是我為獲取當前設計而編寫的代碼。

<com.google.android.material.textfield.TextInputLayout
                android:id="@+id/date_of_birth_input_layout"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                app:endIconDrawable="@drawable/ic_calendar"
                app:endIconMode="custom"
                app:endIconTint="@color/redText"
                app:endIconTintMode="multiply"
                app:hintEnabled="false"
                app:layout_constraintTop_toBottomOf="@id/date_of_birth_title">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/date_of_birth_input"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/activity_horizontal_margin"
                    android:layout_marginTop="6dp"
                    android:layout_marginEnd="@dimen/activity_horizontal_margin"
                    android:focusable="false"
                    android:fontFamily="@font/opensans_regular"
                    android:hint="@string/date_of_birth_hint"
                    android:imeOptions="actionNext"
                    android:inputType="text"
                    android:paddingLeft="10dp"
                    android:paddingTop="13dp"
                    android:paddingRight="10dp"
                    android:paddingBottom="13dp"
                    android:textSize="16sp" />
            </com.google.android.material.textfield.TextInputLayout>

將新的 calendar.xml 添加到 drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:bottom="1.5dp"
    android:top="1.5dp"
    android:right="1.5dp"
    android:drawable="@drawable/background"
    android:gravity="center_horizontal|center_vertical"
    android:width="48dp"
    android:height="48dp"
    />
<item
    android:drawable="@drawable/ic_calendar"
    android:gravity="center_horizontal|center_vertical"
    android:width="36dp"
    android:height="36dp"
    />
</layer-list>

backgroud.xml 像這樣:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" >
<solid android:color="@color/red"  />
<corners android:bottomRightRadius="2.5dp" 
android:topRightRadius="2.5dp"/>
</shape>

並像這樣改變:

app:endIconDrawable="@drawable/calendar"

在此處輸入圖片說明

如果您收到錯誤(向量),您應該將其添加到 build.gradle:

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

暫無
暫無

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

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