Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

need to show textinput layout password toggle image with different color images in on and off state

hanumas1361hanumas1361 USMember ✭✭

Hi,
i have textinput layout and i am able to change the image of the password toggle eye icon in on and off state.
my problem is i wnt to show the images in different colors, if i set some color to app:passwordToggleTint then for images in on and off state are showing with the same color i set.

Please suggest some possible ways to show the eye icon in different colors in on and off state.

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    Create the password_selector.xml file in drawable folder and set passwordToggleDrawable in layout.xmal.
    password_selector.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/image1" android:state_checked="true"/>
    <item android:drawable="@drawable/image2"/>
    </selector>
    

    layout.xaml

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:passwordToggleDrawable="@drawable/password_selector"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Label"/>
    </android.support.design.widget.TextInputLayout>
    

    Refer to: https://stackoverflow.com/a/44190131/11083277

  • hanumas1361hanumas1361 USMember ✭✭
    edited May 2019

    Hi @yelinzh thanks for your response, but thing is already i have implemented the above code in my project, but my problem what i have mentioned here is with above example the images are showing in same color, even if i add image with different colors it is displaying in same,
    i want to show images in different color like black eye in password hide state and blue eye in password visible state

  • JarvanJarvan Member, Xamarin Team Xamurai

    @hanumas1361
    Add app:passwordToggleTint="@null" in TextInputLayout.

    <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:passwordToggleDrawable="@drawable/password_selector"
            app:passwordToggleTint="@null"
            app:passwordToggleEnabled="true"
            >
        <EditText
            ...
            android:inputType="textPassword"
            android:hint="Label"/>
    </android.support.design.widget.TextInputLayout>
    

Sign In or Register to comment.