我使用原生app胶水完全用C制作一个Android应用程序。这个应用程序中根本没有java。我试图找到隐藏软输入键的方法,我试过了
ANativeActivity_hideSoftInput(app->activity, ANATIVEACTIVITY_HIDE_SOFT_INPUT_IMPLICIT_ONLY);
和
ANativeActivity_hideSoftInput(app->activity, ANATIVEACTIVITY_HIDE_SOFT_INPUT_NOT_ALWAYS);
没有运气。我也尝试将它放入我的android清单中:
<activity
android:windowSoftInputMode="stateAlwaysHidden"
...
或
<activity
android:windowSoftInputMode="stateHidden"
...
没有运气。任何方向表示赞赏。
答案 0 :(得分:0)
这是一个非常老的问题,但是我最近也遇到了同样的问题。在此对话中找到以下实现: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();
}