Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JNI based show_soft_input #178

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jancespivo
Copy link

Hi,
this PR is trying to solve not showing soft keyboard on Android.

It might solve #44 🤷

I've tested it on Android version 10 and 12 with xilem (main + winit 0.30.4 (with cherrypicked rust-windowing/winit#3993).

rust-windowing/winit#3787 doesn't work for me at all even it can be better approach for some Android versions.

I've intentionally kept hide_soft_input as is, it works.

@jancespivo jancespivo changed the title Jni show soft input JNI based show_soft_input Dec 28, 2024
@podusowski
Copy link

I think the main problem with the keyboard not showing up on NativeActivity is its View not being in focus. I have hacked the way through by using something like this:

public class MainActivity extends NativeActivity implements OnApplyWindowInsetsListener {
  View getNativeActivityView() {
    // This is hacky as hell, but NativeActivity does not give any proper way of
    // accessing it.
    ViewGroup parent = (ViewGroup) (getWindow().getDecorView());
    parent = (ViewGroup) parent.getChildAt(0);
    parent = (ViewGroup) parent.getChildAt(1);
    return parent.getChildAt(0);
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    View nativeActivityView = getNativeActivityView();
    nativeActivityView.setFocusable(true);
    nativeActivityView.setFocusableInTouchMode(true);
    nativeActivityView.requestFocus();

    ViewCompat.setOnApplyWindowInsetsListener(nativeActivityView, this);

but ultimately switched to GameActivity anyway because of other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants