Issue
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):
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
Solution
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).
Answered By - Cfun
Answer Checked By - Candace Johnson (JavaFixing Volunteer)