-1

i want to create like a "hidden entry" which I use in a data loading screen to preload debit cards after going through a band reader.

My problem it's that i cannot hidden the entry cursor and they see on the screen that "someone it's typing" when they read the card with the band reader.

My code:

<Entry x:Name="cardToRead" 
       Text="{Binding card}"
       InputTransparent="True"
       TextColor="Transparent" />

I want to hide the following (purple line cursor):

cursor color

Is there any property i'm missing, don't found any solution to this! thanks

UPDATE:

Actual solution (not appropriate):

<Entry x:Name="cardToRead" 
       Text="{Binding card}"
       InputTransparent="True"
       TextColor="Transparent"
       WidthRequest=1 />

Cfun upload the best actual solution to solve this if your android api is higher than 29

Leandro Toloza
  • 1,655
  • 1
  • 6
  • 24
  • It is not clear what do you mean by "hidden entry", please explain what do you expect or want to achieve – Cfun Sep 19 '22 at 13:28
  • hidden entry = an entry which is not visible but you can type on it – Leandro Toloza Sep 19 '22 at 13:34
  • how the users will interact with that entry if it is not visible to them ? – Cfun Sep 19 '22 at 13:38
  • is a page that wait you pass the card to the band reader, the entry get focus on that when the page load – Leandro Toloza Sep 19 '22 at 13:39
  • i am sorry but i still didn't get your root problem maybe someone else will. put focus on another ui on that page ? – Cfun Sep 19 '22 at 13:41
  • 1
    are you wanting to programatically enter text in the control (from a scanner or card reader) but NOT let the user enter text from the keyboard? – Jason Sep 19 '22 at 14:17
  • exactly @Jason it's the only way i found // think to do it! – Leandro Toloza Sep 19 '22 at 14:43
  • Does it have to be an entry with Focus? Could you use a disabled Entry, or a Label? – Jason Sep 19 '22 at 14:45
  • i think so, the card reader works like a keyboard so i don't find any proper way to get the text of the reader outside an entry, and if i disable it i can't get the text of the reader! – Leandro Toloza Sep 19 '22 at 14:50
  • is it acceptable for you to keep the entry visible but only apply changes that are done programatically ? ie: if a user enter some data it will be ignored – Cfun Sep 19 '22 at 20:02
  • 1
    @Cfun My problem it's that i use a 3rd party api of a client that only works with an specific debit card reader, so if i don't read properly the card, it would be a problem in future, my question is only for have a better user experiencie, if the user must use the card reader, i need to hide the entry, hide the keyboard and hide the cursor, and when i validate that they read the card properly, i show a new page with all the data masked – Leandro Toloza Sep 19 '22 at 21:56

1 Answers1

1

You can use a custom Entry:

CustomEntry

internal class CustomEntry : EntryHandler
{
    public CustomEntry()
    {
    }

    protected override void ConnectHandler(AppCompatEditText platformView)
    {
        base.ConnectHandler(platformView);
        platformView.ShowSoftInputOnFocus = false;
        //platformView.SetCursorVisible(false); //not sure why it is not working

         //replaced by this approah:
#if ANDROID29_0_OR_GREATER
    platformView.SetTextCursorDrawable(Resource.Drawable.invisible_cursor);
#else
//code to handle it for API< 29, check link in edit section of my answer
#endif
    }
}

MauiProgram.cs

#if ANDROID
builder.ConfigureMauiHandlers((handlers) =>
            {
                handlers.AddHandler(typeof(Entry), typeof(CustomEntry));
            }
#endif

invisible_cursor.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/transparent"></solid>
</shape>

EDIT

SetTextCursorDrawable() was introduced in API29+, to support earlier Android version I invite you to take a look at set textCursorDrawable programmatically, you can handdle that case in the #else of #if ANDROID29_0_OR_GREATER (code above edited).

Cfun
  • 8,442
  • 4
  • 30
  • 62
  • Upvoting this as possible answer, it works on emulator but not on elo devices (Android 8.1), also tested on my phone but it works. With some devices, when you use renderers or handlers, the app crash, and since those are blocked for debugging cannot find a way to know the real issue – Leandro Toloza Sep 20 '22 at 11:52
  • 1
    indeed because `SetTextCursorDrawable()` was only introduced in API 29 check my edit – Cfun Sep 20 '22 at 12:05
  • 1
    would be fun to said that my actual solution (widthrequest = 1) works? it hides the entry cursor and with textcolor=transparent it's "invisible". Until MAUI creates a property to set cursor color or something like that, your answer it's the most appropiate – Leandro Toloza Sep 20 '22 at 12:12
  • lol that tricky and very simple but the most important it works :) You can add it as an answer too – Cfun Sep 20 '22 at 12:15