我有一个LibGDX游戏,我只是注意到在某些时候软键被隐藏了。我不确定这种情况何时发生或发生了什么变化。
考虑到这个问题,我发现它在调试模式下工作正常。然后我尝试了关闭缩小的版本构建,它也运行良好。
我已尝试调整各种设置,但无法在启用缩小功能的情况下隐藏软键。
我在两台不同的Android 6设备上发生了这种情况。
我真的不知道从哪里开始看这个。还有其他人经历过这个吗?
我的UI相关代码在这里:
private void setUpAndroidUi() {
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setKitKatVisibility();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
setJellyBeanVisibility();
} else {
setStandardVisibility();
}
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
private void setStandardVisibility() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void setJellyBeanVisibility() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
@TargetApi(Build.VERSION_CODES.KITKAT)
private void setKitKatVisibility() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
Proguard文件是
# ********** DEAFULT ANDROID SETUP *************
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
# Optimizations: If you don't want to optimize, use the
# proguard-android.txt configuration file instead of this one, which
# turns off the optimization flags. Adding optimization introduces
# certain risks, since for example not all optimizations performed by
# ProGuard works on all versions of Dalvik. The following flags turn
# off various optimizations known to have issues, but the list may not
# be complete or up to date. (The "arithmetic" optimization can be
# used if you are only targeting Android 2.0 or later.) Make sure you
# test thoroughly if you go this route.
-optimizations !code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification
-dontpreverify
# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
# ********** END OF DEAFULT ANDROID SETUP *************
# ********** AMAZON RELATED STUFF *************
-dontwarn com.amazon.**
-keep class com.amazon.** {*;}
-keepattributes *Annotation*
-optimizations !code/allocation/variable
# ********** END AMAZON RELATED STUFF *************
# ********** WE WANT TO KEEP SERIALIZABLE STUFF FOR REFLECTION *********
-keep class * implements java.io.Serializable
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable{
public <init>();
public <init>(android.content.Context);
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# ********** END WE WANT TO KEEP SERIALIZABLE STUFF FOR REFLECTION *********
# ********** OGURY *********
-keepattributes Signature
-keep class sun.misc.Unsafe { *; }
-keep class shared_presage.** { *; }
-keep class io.presage.** { *; }
-keepclassmembers class io.presage.** {
*;
}
-keepattributes *Annotation*
-keepattributes JavascriptInterface
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
-dontwarn org.apache.commons.collections.BeanMap
-dontwarn java.beans.**
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# ********** OGURY BESPOKE
-keep class android.media.**
-dontwarn android.media.**
-dontnote android.media.**
# ********** END OGURY *********
# ********** LIBGDX **************
-verbose
-dontwarn android.support.**
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
-dontwarn com.badlogic.gdx.utils.GdxBuild
-dontwarn com.badlogic.gdx.physics.box2d.utils.Box2DBuild
-dontwarn com.badlogic.gdx.jnigen.BuildTarget*
-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
<init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
}
-keepclassmembers class com.badlogic.gdx.physics.box2d.World {
boolean contactFilter(long, long);
void beginContact(long);
void endContact(long);
void preSolve(long, long);
void postSolve(long, long);
boolean reportFixture(long);
float reportRayFixture(long, float, float, float, float, float);
}
# ********** LIBGDX BESPOKE
-dontwarn java.awt.**
-dontwarn com.google.gwt.**
-keep,includedescriptorclasses class * implements com.badlogic.gdx.utils.Json*
# ********** END LIBGDX **************
# ********** GUAVA **********
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn javax.xml.bind.**
-dontwarn sun.misc.Unsafe
# ********** END GUAVA **********
# ********** ADMOB **********
-keep,includedescriptorclasses public class com.google.android.gms.ads.** {
public *;
}
-keep,includedescriptorclasses public class com.google.ads.** {
public *;
}
# ********** END ADMOB **********
# ********** VUNGLE **********
-keep,includedescriptorclasses class com.vungle.** { public *; }
-keep,includedescriptorclasses class javax.inject.*
-keepattributes *Annotation*
-keepattributes Signature
-keep,includedescriptorclasses class dagger.*
# ********** END VUNGLE **********
# ********** BESPOKE **************
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class android.webkit.WebSettings
-dontwarn android.webkit.WebSettings
-keep,includedescriptorclasses class json.** {*; }
-keepnames class json.** {*; }
-keep class com.scribble.socketshared.messaging.IScrambledMessageReceiver
-dontwarn com.scribble.socketshared.messaging.IScrambledMessageReceiver
-dontwarn org.codehaus.**
-keep class com.facebook.ads.** { *; }
-dontwarn com.flurry.ads.**
-keep class com.flurry.android.** { *; }
-dontwarn com.flurry.android.**
-keep class com.inmobi.ads.** { *; }
-dontwarn com.inmobi.ads.**
-keep class com.inmobi.sdk.** { *; }
-dontwarn com.inmobi.sdk.**
-keep public @com.google.android.gms.common.util.DynamiteApi class * { *; }
# ********** END BESPOKE **************
答案 0 :(得分:0)
将布局代码移动到onWindowFocusChanged
解决了问题。我不能告诉你为什么,但它确实有效。
有一些示例代码here。
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
答案 1 :(得分:0)
必须是因为'@TargetApi'和'@RequiresApi'注释通过反射广告。如果你没有在proguard中添加“keep”并且它看不到该代码的任何路径,它将删除该方法。
因此,如果您将以下内容添加到proguard:
-keep <the package where this code is in>
它应该有用。