Java – button text disappears in KitKat (API level 19)

The main menu of my application (a game) uses standard Android buttons In addition to nexus 7 and Android 4.4 All equipment can work normally except 2 The questions are as follows:

In either case, the text of the button suddenly disappears:

>The button is pressed (occurs immediately when I touch it, and there is no need to release it) > setenabled (Boolean) is called on the button

For example, if I press "load game", the button correctly highlights during the news event, but "load game" disappears completely (the button has empty text)

If I delete all custom styles and behaviors and only use the default Android buttons such as the default font, the problem still exists

If I reduce targetsdkversion to 18 (from 19), everything will work normally even on nexus 7

How has KitKat changed in this regard? I didn't find any questions

My revaluation XML code:

<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>

Important notes on the above Codes:

>The game has two rows of main menus (two buttons per line, a total of four buttons). This main menu is located at the bottom of the screen > text is just a placeholder because the game has its own text file format and reads data from there when creating an activity > even if I completely delete the Android: textcolor and Android: background attributes, the problem still exists In this case, my button will have the default appearance (not its game specific style), but the problem still exists. > Again, the above code is perfect for all (test) equipment except nexus 7 (all equipment except nexus 7 are pre KitKat equipment),

Finally, some information about my global style / theme:

In the Android manifest, I set my application theme to mycustomtheme mycustomtheme. Content of 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>

Finally, my styles The XML is as follows (but I don't seem to reference its style anywhere. It seems to be the old code since we made the full screen of the game, or does Android use it by default?)

<?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>

Solution

Looking at your XML file, I still think there is something wrong with your project

Nexus 7 2013 4.4. 2 (minsdk = 8, targetsdk = 19) does not reproduce this problem:

<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>

Using XML and deleting background / textcolors will not reproduce it:

<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>

Finally, I noticed that Android: textcolor = "button_gamemainmenu_text", which is not the default Android behavior, and suggested that you handle the text color in your own way I firmly believe that deleting this habit will solve the problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>