android - Textview changes background color for no reason -
i have 2 textviews in activity, defined xml - both background color gray. in app, set 1 of textviews background color blue. works expected.
but : when turn device (rotate), or leave app , come again, other textview blue - same color 1 set intentionally...!?
when leave app , start again second textview stays blue. when stop app running (kill) , start again second textview gray. same problem appears rotate device or start app next time.
problem device running 4.1.1. - same app on 2.3.4 device runs no problem.
sdk tools 22.0.1, eclipse juno service release 2 32 bit , windows 7 64 bit
edit : same problem on sdk tools 14, eclipse indigo sr1 32 bit on windows 7 32 bit
i have no idea going on there. kind of undesired magic. please me?
below real source code no modification problem project.
mainactivity.java:
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); } }
acitivity_main.xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <textview android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="100dp" android:background="#cccccc" /> <textview android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="100dp" android:layout_margintop="20dp" android:background="#cccccc" /> </linearlayout>
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <application android:icon="@drawable/ic_launcher" android:label="textview test" > <activity android:name="com.example.test.mainactivity" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
edit 2: make things stranger: if change color of textview2 i.e. #cdcdcd problem not come. in case both colors (textview1 , textview2) identical in xml.
i found solution problem - although not explanation. problem exists if initial colors of both textviews in xml identical. solution therefore give textviews different colors.
so, if have same problem, works me:
acitivity_main.xml: problem
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <textview android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="100dp" android:background="#cccccc" /> <textview android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="100dp" android:layout_margintop="20dp" android:background="#cccccc" /> </linearlayout>
acitivity_main.xml: without problem
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <textview android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="100dp" android:background="#ffcccccc" /> <textview android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="100dp" android:layout_margintop="20dp" android:background="#fecccccc" /> </linearlayout>
in other words have used different color (actually here different transparency) - , problem gone. not believe if told me.
Comments
Post a Comment