Custome textCursorDrawable is not reflected in Android 10 and higher devices

44 views Asked by At

XML CODE

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

        android:id="@+id/email_et_ll"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:boxStrokeColor="@color/input_text_custom_outline_color"
        app:boxStrokeErrorColor="@android:color/holo_red_light"
        app:hintTextColor="@color/yellow"
        android:layout_marginStart="16sp"
        android:layout_marginTop="16sp"
        android:layout_marginEnd="16sp"
        android:hint="@string/hello_gmail_com"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/login_info_txt"
        app:shapeAppearance="@style/input_text_rounded_corner"
        app:startIconDrawable="@drawable/baseline_email_24">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/email_et"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:cursorVisible="true"
            android:textCursorDrawable="@drawable/cursor_bg"
            />

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

This is my XML code, where I have made a input text field with custom textCursorDrawable, but this change is only reflected in the android 8,9 but not in the higher version , how to fix this? I need help.

Here are the screenshots.

Android-8

enter image description here

Android-9

enter image description here

Android-10

enter image description here

same for higher versions 11,12 (tested).

2

There are 2 answers

0
Jaydip Chavda On

use the custom theme in your TextInputLayout android:theme="@style/TextInputEditText"

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/loginEmailTextInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/_20sdp"
        android:layout_marginTop="@dimen/_10sdp"
        android:layout_marginEnd="@dimen/_20sdp"
        app:boxStrokeWidth="0dp"
        app:boxStrokeWidthFocused="0dp"
        app:hintEnabled="false"
        android:theme="@style/TextInputEditText"
        app:layout_constraintTop_toBottomOf="@+id/textView6"
        app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Medium"
        app:startIconDrawable="@drawable/emailicon"
        app:startIconTint="@color/greycolor"/>

style.xml

    <style name="TextInputEditText" parent="">
        <item name="colorControlActivated">@color/black</item>
    </style>
1
Rahul Rokade On

I hope this code your side working Theme.xml

<style name="OutlinedRoundedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    <item name="shapeAppearanceOverlay">
        @style/ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded
    </item>
</style>
<style name="ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">32dp</item>
</style>
<style name="OutlinedRoundRahulBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    <item name="boxBackgroundMode">outline</item>
    <item name="boxCornerRadiusBottomEnd">32dp</item>
    <item name="boxCornerRadiusBottomStart">32dp</item>
    <item name="boxCornerRadiusTopEnd">32dp</item>
    <item name="boxCornerRadiusTopStart">32dp</item>
</style>

activity code

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_margin="10dp"
    android:layout_centerInParent="true"
    android:layout_below="@id/box_one">
    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:hint="Username"
        android:layout_margin="@dimen/_10ssp"
        app:startIconDrawable="@drawable/ic_person"
        app:startIconContentDescription="Username"
        style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton">
        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edtUsername"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:maxLines="1"
            android:textSize="14sp"
            android:textColor="@color/black"/>
    </com.google.android.material.textfield.TextInputLayout>
    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/OutlinedRoundedBox"
        android:background="@android:color/transparent"
        android:hint="Password"
        android:layout_margin="@dimen/_10ssp"
        app:startIconDrawable="@drawable/ic_key"
        android:foregroundTintMode="screen"
        app:startIconContentDescription="Username">
        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edtPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            app:textInputLayoutFocusedRectEnabled="true"
            android:maxLines="1"
            android:textSize="14sp"
            android:textColor="@color/black"/>
    </com.google.android.material.textfield.TextInputLayout>
    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/OutlinedRoundRahulBox"
        android:background="@android:color/transparent"
        android:hint="Confirm Password"
        android:layout_margin="@dimen/_10ssp"
        app:startIconDrawable="@drawable/ic_key"
        android:foregroundTintMode="screen"
        app:startIconContentDescription="Username">
        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edt_confirm_Password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            app:textInputLayoutFocusedRectEnabled="true"
            android:maxLines="1"
            android:textSize="14sp"
            android:textColor="@color/black"/>
    </com.google.android.material.textfield.TextInputLayout>
    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/btn_login"
        android:layout_width="180dp"
        android:layout_height="45dp"
        android:textColor="@color/white"
        android:text="LOGIN"
        android:textSize="16sp"
        android:textStyle="bold"
        android:layout_margin="@dimen/_10ssp"
        android:paddingRight="10dp"
        android:paddingLeft="10dp"
        android:background="@drawable/blue_solid_rounded_button"
        android:layout_gravity="center_horizontal"/>
    <TextView
        android:id="@+id/txt_changePass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorTextGray"
        android:padding="@dimen/_5sdp"
        android:textSize="10sp"
        android:text="Change Password Screen"
        android:gravity="center"
        android:layout_margin="10dp"
        android:layout_gravity="center"/>
</LinearLayout>

color code

<color name="colorPrimary">#00B1D2</color>
<color name="colorPrimaryDark">#0297B3</color>
<color name="colorAccent">#A3A1A1</color>