Android TextView text is showing up as black squares?

…衆ロ難τιáo~ 提交于 2019-12-25 02:44:17

问题


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?

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

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

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.

EDIT: 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.


回答1:


Check what u have in on start and on stop methods, it is for sure painting what u have typed earlier.




回答2:


Try putting

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




回答3:


I encountered the same situation.

Just make sure your deleting view(which uses opengl) texture action in the thread you created it.

In your case, GameView is the key.



来源:https://stackoverflow.com/questions/25224364/android-textview-text-is-showing-up-as-black-squares

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!