TextView和Button textColor消失

时间:2014-09-27 06:59:34

标签: android button textview textcolor

我遇到了TextView的问题以及作为Fragment一部分的三个按钮。文本颜色偶尔会消失(大约每隔5或6次创建一个片段)。文字和背景仍然很好。我只有textColor有问题。这是一个使用libgdx从一个片段运行的游戏。菜单等从单独的Frag运行。

Link to pics

这是xml。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         >

        <Button
            android:id="@+id/btn_quit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="35dp"
            android:background="#00000000"
            android:text="MENU"
            android:textColor="@color/red"
            android:textSize="19sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/btn_play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/btn_quit"
            android:layout_centerHorizontal="true"
            android:background="#00000000"
            android:text="PLAY"
            android:textColor="#ffed0d0d"
            android:textSize="19sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/btn_score"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/btn_quit"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="35dp"
            android:background="#00000000"
            android:text="SCORE"
            android:textColor="@color/meep_red"
            android:textSize="19sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/scoreText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_above="@id/btn_play"
            android:layout_marginBottom="35dp"
            android:textSize="50sp" />

        <LinearLayout
            android:id="@+id/banner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal" >
        </LinearLayout>
    </RelativeLayout>

</FrameLayout>

这是Java。

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.diescreen_fragment, container,
                false);

        /* Determine whether the Activity requested to show ads */
        Bundle args = getArguments();
        boolean showAd = false;
        int score = 0;
        if(args != null){
            showAd = args.containsKey(ARG_SHOW_AD) ? args.getBoolean(ARG_SHOW_AD) : false;
            score = args.containsKey(SCORE) ? args.getInt(SCORE) : 0;
        }

        /* Initialize advertisements */
        mBanner = new RevMobBannerAd(getActivity());
        mFullscreen = new RevMobFullscreenAd(getActivity());
        mFullscreen.setFullscreenAdListener(new FullscreenAdListener(){
            @Override
            public void onDisplay() {
                canClick = true;
            }

            @Override
            public void onAdClicked() {
                canClick = true;
            }

            @Override
            public void onAdDismissed() {
                canClick = true;
            }
        });

        /* Show FullscreenAd if requested */
        if(showAd && net.hasConnection()){
            canClick = false;
            mFullscreen.showAd();
        }

        font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/PLUMP.TTF");

        playSound = GamePrefsHelper.isSoundOn(getActivity());
        bannerView = (ViewGroup)view.findViewById(R.id.banner);
        mBanner.showAd(bannerView);
        sound = MediaPlayer.create(getActivity(), R.raw.btn_sound);
        scoreView = (TextView)view.findViewById(R.id.scoreText_dieScreen);
        scoreView.setText(String.valueOf(score));

        (playBtn = (Button)view.findViewById(R.id.btn_play)).setOnTouchListener(this);
        (quitBtn = (Button)view.findViewById(R.id.btn_quit)).setOnTouchListener(this);
        (scoreBtn = (Button)view.findViewById(R.id.btn_score)).setOnTouchListener(this);
        playBtn.setTypeface(font);
        quitBtn.setTypeface(font);
        scoreBtn.setTypeface(font);
        view.requestLayout();

        return view;
    }

@ color / red是我的自定义红色,显示在btn_play中。我尝试过使用硬编码颜色和从资源文件中提取,但没有成功。我已经尝试将Buttons和TextView剥离到最小 - 没有颜色,标准背景和没有字体 - 然后添加透明背景,字体和颜色。背景,文字,字体和功能总是很好。文字颜色是唯一消失的东西。

最后我还试图修复这些症状。

   view.requestLayout();

记录输出

09-27 02:49:23.102: D/OpenGLRenderer(29488): GL error from OpenGLRenderer: 0x501
09-27 02:49:23.102: E/OpenGLRenderer(29488):   GL_INVALID_VALUE
09-27 02:49:23.805: D/[RevMob](29488): Fullscreen static for orientations
09-27 02:49:23.805: D/libc(29488): Forward DNS query to netd(h=creatives.revmob.com s=^)
09-27 02:49:24.992: I/[RevMob](29488): Banner loaded - 527a5678b8f9d1984b00014b
09-27 02:49:25.070: D/dalvikvm(29488): GC_FOR_ALLOC freed 615K, 12% free 17229K/19491K, paused 70ms, total 70ms
09-27 02:49:25.086: I/dalvikvm-heap(29488): Grow heap (frag case) to 19.669MB for 2908176-byte allocation
09-27 02:49:25.141: D/dalvikvm(29488): GC_FOR_ALLOC freed 62K, 11% free 20007K/22371K, paused 52ms, total 52ms
09-27 02:49:25.172: D/OpenGLRenderer(29488): GL error from OpenGLRenderer: 0x501
09-27 02:49:25.172: E/OpenGLRenderer(29488):   GL_INVALID_VALUE
09-27 02:49:25.922: I/Choreographer(29488): Skipped 44 frames!  The application may be doing too much work on its main thread.
09-27 02:49:26.492: D/libc(29488): Forward DNS query to netd(h=creatives.revmob.com s=^)
09-27 02:49:26.719: D/dalvikvm(29488): GC_FOR_ALLOC freed 357K, 11% free 20104K/22371K, paused 56ms, total 56ms
09-27 02:49:26.727: I/dalvikvm-heap(29488): Grow heap (frag case) to 22.477MB for 2908176-byte allocation
09-27 02:49:26.781: D/dalvikvm(29488): GC_FOR_ALLOC freed 38K, 10% free 22905K/25251K, paused 58ms, total 58ms
09-27 02:49:27.375: D/libc(29488): Forward DNS query to netd(h=android.revmob.com s=^)
09-27 02:49:27.406: I/[RevMob](29488): Fullscreen loaded - 527a5678b8f9d1984b00014b
09-27 02:49:31.047: D/OpenGLRenderer(29488): GL error from OpenGLRenderer: 0x501
09-27 02:49:31.047: E/OpenGLRenderer(29488):   GL_INVALID_VALUE

我在stackoverflow上搜索了很多帖子,并研究了Android Developer网站以更好地理解这个问题。没有运气!

请帮助stackoverflow!你是我唯一的希望! ;)

0 个答案:

没有答案