我的应用程序(一个游戏)的主菜单使用标准的Android按钮。在除了运行着Android 4.4.2的Nexus 7设备之外的所有设备上,它都可以正常工作。问题如下:
无论以下哪种情况发生,按钮的文本会突然消失:
- 按钮被按下时(当我触摸它时,它立即发生,无需释放) - setEnabled(boolean)被调用到该按钮上
例如,如果我按下“加载游戏”按钮,在按下事件期间,该按钮会正确地被高亮显示,但是“加载游戏”会完全消失(按钮的文本为空)。
如果我删除所有自定义样式和行为,并仅使用带有默认字体等的默认Android按钮,则问题仍然存在。 如果我将targetSdkVersion降低至18(从19),则即使在Nexus 7上也能正常工作。 任何想法在这方面KitKat中发生了什么变化吗?我没有找到任何可疑的事情。
我的相关XML代码:
最后,我的
无论以下哪种情况发生,按钮的文本会突然消失:
- 按钮被按下时(当我触摸它时,它立即发生,无需释放) - setEnabled(boolean)被调用到该按钮上
例如,如果我按下“加载游戏”按钮,在按下事件期间,该按钮会正确地被高亮显示,但是“加载游戏”会完全消失(按钮的文本为空)。
如果我删除所有自定义样式和行为,并仅使用带有默认字体等的默认Android按钮,则问题仍然存在。 如果我将targetSdkVersion降低至18(从19),则即使在Nexus 7上也能正常工作。 任何想法在这方面KitKat中发生了什么变化吗?我没有找到任何可疑的事情。
我的相关XML代码:
<TableLayout
android:id="@+id/layoutGameMainmenu"
android:layout_width="wrap_content"
android:layout_height="83dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:gravity="center_vertical"
android:visibility="gone" >
<TableRow>
<Button
android:id="@+id/buttonLoadGame"
android:layout_width="174dip"
android:layout_height="40dip"
android:layout_marginBottom="2dip"
android:layout_marginRight="30dip"
android:background="@drawable/button_gamemainmenu"
android:text="buttonLoadGame"
android:textColor="@color/button_gamemainmenu_text"
android:textScaleX="0.9"
android:textSize="16dp" />
<Button
android:id="@+id/buttonSettings"
android:layout_width="174dip"
android:layout_height="40dip"
android:layout_marginBottom="2dip"
android:layout_marginLeft="30dip"
android:background="@drawable/button_gamemainmenu"
android:text="buttonSettings"
android:textColor="@color/button_gamemainmenu_text"
android:textScaleX="0.9"
android:textSize="16dp" />
</TableRow>
<TableRow>
<Button
android:id="@+id/buttonStartGame"
android:layout_width="174dip"
android:layout_height="40dip"
android:layout_marginBottom="1dip"
android:layout_marginRight="30dip"
android:background="@drawable/button_gamemainmenu"
android:text="buttonStartGame"
android:textColor="@color/button_gamemainmenu_text"
android:textScaleX="0.9"
android:textSize="16dp" />
<Button
android:id="@+id/buttonQuit"
android:layout_width="174dip"
android:layout_height="40dip"
android:layout_marginBottom="1dip"
android:layout_marginLeft="30dip"
android:background="@drawable/button_gamemainmenu"
android:text="buttonQuit"
android:textColor="@color/button_gamemainmenu_text"
android:textScaleX="0.9"
android:textSize="16dp" />
</TableRow>
</TableLayout>
关于上面的代码,有一些重要的注意事项:
- 游戏有一个两行主菜单(每行有两个按钮,总共4个按钮),并且这个主菜单位于屏幕底部。
- 文字为占位符,因为游戏有自己的文本文件格式,并在Activity创建时从中读取数据。
- 即使我完全删除
android:textColor
和android:background
属性,问题依然存在。 在这种情况下,我的按钮将具有默认外观(而不是它们特定于游戏的样式),但问题仍然存在。 - 再次强调:上面的代码在除Nexus 7以外的所有(经过测试的)设备上都可以完美运行(我的所有设备都是预装KitKat之前的设备)。
最后,一些有关全局样式/主题的信息:
在AndroidManifest中,我将我的Application
主题设置为MyCustomTheme
。 mycustomtheme.xml
的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyCustomTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:soundEffectsEnabled">false</item>
</style>
</resources>
最后,我的
styles.xml
如下(但似乎我没有从任何地方引用它的样式,这似乎是我们将游戏全屏时的旧代码,或者Android在默认情况下是否会使用它?):<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
</style>
<style name="Theme.TranslucentWoTitle" parent="android:Theme.Translucent">
<item name="android:windowNoTitle">true</item>
</style>
</resources>