Android的TextView的文本显示为黑色方块? [英] Android TextView text is showing up as black squares?

查看:2508
本文介绍了Android的TextView的文本显示为黑色方块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序一个TextView,直到我暂停的应用程序(由pressing家),并再次启动它工作正常。它应该只是恢复活动,但由于某些原因,TextView中不能正常显示文本将恢复活动后。该文本是显示为黑色方块,就像这样:

I have a TextView in my application that works fine until I pause the application (by pressing home) and launch it again. It should just resume the activity, but for some reason the TextView doesn't display the text properly after it resumes the activity. The text is showing up as black squares, like this:

http://i.stack.imgur.com/5mtvy.png

有谁知道如何解决这一问题?

Does anyone know how to fix this?

编辑:这是我的code:
TextView的是在具有GLSurfaceView(称为GameView)和该一个TextView顶部上的布局的xml创建。这里的XML code:

Here's my code: The TextView is created in a layout xml that has a GLSurfaceView (called GameView) and on top of that a TextView. Here's the xml code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="MainActivity" >

    <GameView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/gv"
        />

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:textColor="@android:color/black"
        android:id="@+id/tv" />

</RelativeLayout>

这里是code在MainActivity类onCreate方法:

And here is the code in the MainActivity class onCreate method:

    setContentView(R.layout.activity_main);
    GameView gameView = (GameView) findViewById(R.id.gv);
    TextView textView = (TextView) findViewById(R.id.tv);

在onPause的,onResume,在onStart,方法的onStop没有什么相关的TextView。
TextView是被保存到了MainActivity一个实例变量以后,TextView.setText()被调用来设置TextView的文本。

The onPause, onResume, onStart, onStop methods have nothing related to the TextView. The TextView is saved into an instance variable for MainActivity and later, TextView.setText() is called to set the text of the TextView.

编辑:我是能够解决注释掉一行这样的问题:GLES20.glDeleteTextures(...),这是被称为的onPause()我不知道这是怎么甚至关系或者为什么调用这个函数引起的问题,但是当我注释掉问题消失了,当我把这个行回到问题回来吧。如果任何人都可以解释怎么一涉及其他,这将是极大的AP preciated。

I was able to fix this problem by commenting out one line: GLES20.glDeleteTextures(...) that was being called onPause() I have NO idea how this is even related or why calling this function caused that issue, but when I comment it out the problem goes away and when I bring this line back the problem comes back with it. If anyone can explain how one relates to the other, it would be greatly appreciated.

推荐答案

尝试把

@Override
public void onResume() {
    super.onResume(); // Always call the superclass method first

TextView textView = (TextView) findViewById(R.id.tv);
textView.forceLayout();

}

让我知道,如果这能解决你的问题或不?

Let me know if this solves your problem or not?

这篇关于Android的TextView的文本显示为黑色方块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆