Home > database >  how to change textcolor of text input edittext
how to change textcolor of text input edittext

Time:01-25

I have been using TextInputEditText with TextInputLayout. I want to change the color of TextInputEditTextbut it doesn't work. (Only preview text color changes, i set preview text programitacallyy, but text input edit text color not changing)

below is my xml file

<style name="EditTextBaseStyle" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/black</item>
        <item name="editTextColor">@color/black</item>
        <item name="itemTextColor">@color/black</item>
        <item name="colorControlNormal">@color/black</item>
    </style>

layout file

<com.google.android.material.textfield.TextInputLayout
            android:id="@ id/input_layout"
            android:layout_width="match_parent"
            android:layout_height="@dimen/card_view_height"
            android:layout_gravity="center_vertical"
            android:background="@color/transparent"
            android:gravity="center_vertical"
            android:paddingEnd="@dimen/dimen_8dp"
            android:textColorHint="@color/gray3"
            app:boxBackgroundColor="@color/transparent"
            app:boxStrokeWidth="0dp"
            app:boxStrokeWidthFocused="0dp"
            app:expandedHintEnabled="true"
            app:hintTextColor="@color/gray3"
            tools:hint="Hint text">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@ id/value"
                android:textAppearance="@style/EditTextBaseStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@null"
                android:fontFamily="@font/sf_pro_text_medium"
                android:gravity="center_vertical"
                android:paddingStart="@dimen/dimen_16dp"
                android:paddingEnd="@dimen/dimen_16dp"
                android:textSize="@dimen/b1" />

        </com.google.android.material.textfield.TextInputLayout>

CodePudding user response:

Add below line in your style.xml file under resources

<style name="EditTextTheme" parent="Widget.Design.TextInputLayout">
    <item name="colorControlNormal">#400060AB</item>
    <item name="colorControlActivated">#0060AB</item>
</style>

Add below code in your layout xml

<com.google.android.material.textfield.TextInputLayout
    android:id="@ id/et_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="50dp"
    android:layout_marginRight="20dp"
    android:backgroundTint="#516CDC"
    android:hint="Enter something here"
    android:theme="@style/EditTextTheme">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@ id/et_input"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:textColor="#0060AB"
        android:textSize="12sp" />

</com.google.android.material.textfield.TextInputLayout>

Output

enter image description here enter image description here enter image description here

CodePudding user response:

Do it simply like this

    editText.setTextColor(color);

OR

editText.setTextColor(Color.parseColor("#f454f"));
  •  Tags:  
  • Related