Note that there are some explanatory texts on larger screens.

plurals
  1. POTextview changes background color for no reason
    primarykey
    data
    text
    <p>I have two textviews in an activity, defined by xml - both with background color gray. In my app, I set one of the textviews background color to blue. This works as expected.</p> <p><strong>BUT : When I turn the device (rotate), or leave the app and come back again, the other textview is also blue - same color as the one set intentionally...!?</strong></p> <p>When I leave the app and start it again the second textview stays blue. When I stop the app from running (kill) and start it again the second textview is gray. But same problem appears as soon as I rotate the device or start the app the next time.</p> <p>Problem device is running 4.1.1. - same app on 2.3.4 device runs with no problem.</p> <p>SDK Tools 22.0.1, Eclipse Juno Service Release 2 32 bit , Windows 7 64 bit</p> <p><strong>EDIT :</strong> Same problem on SDK Tools 14, Eclipse Indigo SR1 32 bit on Windows 7 32 bit</p> <p>I have no idea what is going on there. It is some kind of undesired MAGIC. Could you please help me?</p> <p><img src="https://i.stack.imgur.com/5wzUL.png" alt="Before"> <img src="https://i.stack.imgur.com/5Cvfg.png" alt="After"></p> <p>Below is the real source code with no modification from the problem project.</p> <p><strong>MainActivity.java:</strong></p> <pre><code>package com.example.test; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv1 = (TextView) findViewById(R.id.textView1); tv1.setBackgroundColor(0xff33b5e5); } } </code></pre> <p><strong>acitivity_main.xml:</strong></p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="100dp" android:background="#cccccc" /&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="fill_parent" android:layout_height="100dp" android:layout_marginTop="20dp" android:background="#cccccc" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>AndroidManifest.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="TextView Test" &gt; &lt;activity android:name="com.example.test.MainActivity" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p><strong>EDIT 2:</strong> To make things even stranger: If I change color of textview2 slightly to i.e. #cdcdcd the problem does NOT come. It is only in case both colors (textview1 and textview2) are identical in XML.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload