gpt4 book ai didi

c - 如何隐藏软导航键(android)

转载 作者:行者123 更新时间:2023-12-05 07:51:04 24 4
gpt4 key购买 nike

我正在使用 native 应用胶水来制作一个完全用 C 编写的 android 应用程序。这个应用程序中根本没有 java。我在想办法隐藏软输入键,我试过了

ANativeActivity_hideSoftInput(app->activity, ANATIVEACTIVITY_HIDE_SOFT_INPUT_IMPLICIT_ONLY);

ANativeActivity_hideSoftInput(app->activity, ANATIVEACTIVITY_HIDE_SOFT_INPUT_NOT_ALWAYS);

运气不好。我也试过将它放入我的 android list 中:

<activity 
android:windowSoftInputMode="stateAlwaysHidden"
...

<activity
android:windowSoftInputMode="stateHidden"
...

运气不好。任何方向表示赞赏。

最佳答案

这是一个非常古老的问题,但我最近遇到了同样的问题。在此对话中发现了以下实现:https://www.gamedev.net/forums/topic/674511-auto-hide-nav-bar-on-android-app-ndk/

要隐藏顶部的导航栏,您需要将此行添加到您的 AndroidManifest.xml

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

你可以这样添加

        <activity android:name="android.app.NativeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

要隐藏底部的导航栏需要编写如下代码。

void AutoHideNavBar(struct android_app* state)
{
JNIEnv* env;
state->activity->vm->AttachCurrentThread(&env, NULL);

jclass activityClass = env->FindClass("android/app/NativeActivity");
jmethodID getWindow = env->GetMethodID(activityClass, "getWindow", "()Landroid/view/Window;");

jclass windowClass = env->FindClass("android/view/Window");
jmethodID getDecorView = env->GetMethodID(windowClass, "getDecorView", "()Landroid/view/View;");

jclass viewClass = env->FindClass("android/view/View");
jmethodID setSystemUiVisibility = env->GetMethodID(viewClass, "setSystemUiVisibility", "(I)V");

jobject window = env->CallObjectMethod(state->activity->clazz, getWindow);

jobject decorView = env->CallObjectMethod(window, getDecorView);

jfieldID flagFullscreenID = env->GetStaticFieldID(viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
jfieldID flagHideNavigationID = env->GetStaticFieldID(viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");

int flagFullscreen = env->GetStaticIntField(viewClass, flagFullscreenID);
int flagHideNavigation = env->GetStaticIntField(viewClass, flagHideNavigationID);

int flag = flagFullscreen | flagHideNavigation;

env->CallVoidMethod(decorView, setSystemUiVisibility, flag);

state->activity->vm->DetachCurrentThread();
}

关于c - 如何隐藏软导航键(android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35501124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com