java – 按钮文本消失在KitKat(API级别19)
我的应用程序(一个游戏)的主菜单使用标准的
Android按钮.除了Nexus 7与Android 4.4.2之外,所有设备都可以正常工作.问题如下:
在任何一种情况下,按钮的文本突然消失: >按钮被按下(当我触摸它时立即发生,不需要释放它) 例如,如果我按“加载游戏”,按钮在新闻事件期间正确突出显示,但“加载游戏”完全消失(该按钮有空文本). 如果我删除所有自定义的样式和行为,并且仅使用默认的字体等的默认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个按钮),此主菜单位于屏幕底部 最后,关于我的全球风格/主题的一些信息: 在AndroidManifest中,我将我的应用程序主题设置为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> 解决方法
看看你的XML文件,我仍然认为你的项目出了问题.
Nexus 7 2013 4.4.2(minSDK = 8,targetSDK = 19)这个最小的例子并不重现这个问题: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> 使用XML和删除background / textcolors也不会重现它: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <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"> <TableRow> <Button android:id="@+id/buttonLoadGame" android:layout_width="174dip" android:layout_height="40dip" android:layout_marginBottom="2dip" android:layout_marginRight="30dip" android:text="buttonLoadGame" 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:text="buttonSettings" 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:text="buttonStartGame" 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:text="buttonQuit" android:textScaleX="0.9" android:textSize="16dp" /> </TableRow> </TableLayout> </RelativeLayout> 最后,我注意到android:textColor =“button_gamemainmenu_text”,这不是默认的Android行为,并建议您以自己的方式处理文本颜色.我坚信,删除这个习惯行为将解决问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |