I've got a strange issue where when I'm on a page (Page 1) that has an Entry, I tap the Entry to give it focus, then I tap a button that calls Navigation.PushModalAsync to bring up another page (Page 2) which only has a Label on it, I type on the physical keyboard, then hit back to go back to Page 1, I magically find the text I'd typed when on Page 2 is in the Entry on Page 1!
That feels like a bug to me? How can I stop keyboard entry going to Page 1 when Page 2 is displayed?
I'm using VS2022, Xamarin Forms 5.0.0.2196, and an Android Emulator using Android 9 / API 29.
public class Page1 : ContentPage
{
public Page1()
{
StackLayout stackLayout = new StackLayout();
stackLayout.Children.Add(new Label() { Text = "Page 1. Tap in Entry A, and then tap the Click Me button." });
stackLayout.Children.Add(new Entry() { Placeholder = "Entry A" });
Button button = new Button() { Text = "Click Me" };
stackLayout.Children.Add(button);
Content = stackLayout;
button.Clicked += Button_Clicked;
}
private async void Button_Clicked(object sender, EventArgs e)
{
ContentPage page2 = new ContentPage();
page2.Content = new Label() { Text = "Page 2. Type some letters on the physical keyboard, and then hit the Back button to get back to Page 1." };
await Navigation.PushModalAsync(new NavigationPage(page2));
}
}
I had test your code on different versions of Android. And at first, when you tap the button, the Entry should be unfocused. Because if I tapped the Entry and then tapped the other field, the cursor will disappear from the Entry. But when I typed on the physical keyboard, the soft keyboard will appear and the text I'd typed will show on the Entry on the Android 9.0.
On the Android 10.0, the soft keyboard will appear but the text will not show on the Entry.
On the Android 11.0, both the keyboard and the text don't show.
In addition, on the Android 9.0, if you don't have tapped the Entry at first, the soft keyboard and the text will not show when you typed on the physical keyboard.
So, this should be the different handling of physical input events in Xamarin.Forms in different Android version. You can also post the issue to the Xamarin.Forms to get the answer.
Related
I am using Unity in my Android project. There are input fields in my app. As soon as I click on the field the keyboard pops up. I want the keyboard to only show up when there is a double-tap on the field. But I am not able to get it to work and I have tried several ways.
Requirement 1: Single tap shouldn't open keyboard
Requirement 2: Double tap should open keyboard
I tried OnPointerClick method of IPointerClickHandler but this doesn't seem to work. I used this code in one of the scripts attached to input field with IPointerClickHandler.
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.clickCount == 2)
{
Debug.Log("UNITY - Double click");
}
else if (eventData.clickCount == 1)
{
Debug.Log("UNITY - Single click");
}
}
Then there is also the question of how to hide the keyboard or prevent it from opening on single tap. This also I am not able to solve. I started with clicking the Hide Soft Keyboard in control setting of InputField in Unity editor. But surprisingly this starts opening a keyboard which has mobile input.
Can someone help? I have been stuck on this for some time I can't seem to be getting anywhere.
I have an Ionic app that must be in landscape mode. When a user tap on an input field to type, the keyboard comes up, so the user can only see the header, footer and the keyboard, thus the user can't see what he is typing. I saw on native apps when I do the same thing, the keyboard comes up with a separate textbox, which will be perfect for my Ionic app. How can I do it in Ionic? Here are some screenshots:
The screen in landscape mode before typing
The screen when typing starts
The screen on native apps when typing
Try to use scrollAssist: true for IonicModule.
IonicModule.forRoot(MyApp, {
scrollAssist: true
}),
I got it to work. Looks like the only way to fix this is to hide the header and footer when keyboard is showing and show header and footer when keyboard is hiding. I also had to remove some margins so that the focused input is at the top. Here's my code I added in the app.component.ts:
keyboard.onKeyboardShow().subscribe(() => {
let headers = document.querySelectorAll("ion-header"); //Get all headers
headers[headers.length - 1].setAttribute("style", "display: none"); //Hide ACTIVE header
let footers = document.querySelectorAll("ion-footer"); //Get all footers
footers[footers.length - 1].setAttribute("style", "display: none"); //Hide ACTIVE footer
let contents = document.querySelectorAll("ion-content"); //Get all content
contents[contents.length - 1].querySelector("div.scroll-content").removeAttribute("style"); // Remove styling from content (margins)
});
keyboard.onKeyboardHide().subscribe(() => {
let headers = document.querySelectorAll("ion-header"); //Get all headers
headers[headers.length - 1].removeAttribute("style"); //Show ACTIVE header again
let footers = document.querySelectorAll("ion-footer"); //Get all footers
footers[footers.length - 1].removeAttribute("style"); //Show ACTIVE footer
let contents = document.querySelectorAll("ion-content"); //Get all content
contents[contents.length - 1].querySelector("div.scroll-content").setAttribute("style", "margin-top: 56px; margin-bottom: 56px;"); //Set styling again (margins)
});
I am working with the QuillJS editor (awesome!) for a multi-platform forum web app and I'm trying to solve a problem with Android's webview (same thing happens in the Chrome app). Basically when I long-press to select some text on the top lines of the post the native context menu covers the Quill toolbar.
I've added css padding-top to the editor element to get the result in the next screen shot, but it looks weird to have the empty space at the top of the edit area when there's no context menu.
Other things I've discovered: you can't drag the context menu down, and tapping outside it or pressing the back button deselect the text. You can keep the context menu from showing by handling the oncontextmenu event, but then there's no way to cut/copy/paste.
Are there any alternatives? It would be cool if there were cut/copy/paste options for the Quill toolbar, which would allow me to just inhibit the context menu for the editor div, but I couldn't find such options.
EDIT: To clarify, I didn't actually change the orientation of the popup, but by switching to the "Bubble" theme the toolbar becomes a popup that appears under the selected text by default.
Answering my own question.
I changed the orientation of the pop-up so that it is below the selected text. Here's the initialization script:
<!-- Initialize Quill editor -->
<script>
var quill = new Quill('#editor-container', {
modules: {
toolbar: [
['bold'],
['italic'],
[{ 'color': [] }],
[{ size: ['small', false, 'large', 'huge'] }],
['image'],
['link']
]
},
placeholder: '(type your message here)',
theme: 'bubble' // 'snow' or 'bubble'
});
quill.on('text-change', function (delta, oldDelta, source) {
if (source === 'api') {
console.log("An API call triggered this change.");
} else if (source === 'user') {
console.log("A user action triggered this change.");
}
var htmlContent = quill.root.innerHTML;
$('#body').val(htmlContent);
});
window.onload = function () {
quill.focus();
};
</script>
I am preparing app using phonegap.In app i have displayed list of data and one search bar.User can search by particular name.Here i have used jquery ajax.It is working fine.My problem is when click on search bar soft keyboard will open automatically.After enter the text just click on "GO" button in soft keyboard i call search method.It is also working fine.But cursor is still visible on search bar.I want to make the cursor invisible on clicking "GO" button from soft keyboard.My code is,
function submitOnEnter(inputElement, event)
{
console.log("KEY OCDE:: "+event.keyCode);
if (event.keyCode == 13)
{
caSearch();
}
}
Please guide me to over come this.
Use these attributes, which will make it impossible to select your edittext and will therefore deselect if for you.
yourEditText.setFocusable( false );
yourEditText.setFocusableInTouchMode( false );
Immediately afterwards, reverse these two prices of code
yourEditText.setFocusable( true );
yourEditText.setFocusableInTouchMode( true );
That should remove the cursor from search bar for you
does anybody knows how to force keyboard open on android browser (4.0 - maybe less)?
i tried this solution and it does not worked for me.
in project i am trying to get a text input working, but after submitting (intercept by jQuery) it holds focus but the keyboard disappears.
snippets:
$('#typer').blur(function () {
$(this).focus().click();
});
$('#typer').bind('keyup', function (e) {
var input = $.trim($(this).val());
// some lines of code..
$(this).val('').focus(); // clean up
}
iOS is also interesting.. but not tested yet.
Android pulls up soft keyboard whenever text input field is in focus. "Go" or "Done" button on Android works as form submit, therefore input text looses focus and keyboard disappears. User expects the keyboard to disappear after "Go", "Done" or "Enter" is pressed - so Android follows this rule. Forcing re-focus on field's blur will not do much since technically you moved to a different window.
$('body').click(function() { $('#typer').focus(); }
can provide a partial solution, whereby user has to click once anywhere in the body of the page for the typer to re-gain focus. It causes OS to move back to browser Activity and focus the input field. This fiddle shows it as an example: http://jsfiddle.net/Exceeder/Z6SFH/ (use http://jsfiddle.net/Exceeder/Z6SFH/embedded/result/ on your Android device)
Other than writing a PhoneGap-like wrapper to control imeOptions of the keyboard, I am not aware of any solution that can solve this problem.