但是:当我转动设备(旋转),或离开应用程序并再次返回时,其他文本视图也是蓝色 – 与故意设置的颜色相同……!
当我离开应用程序并再次启动它时,第二个textvIEw保持蓝色.当我停止运行应用程序(kill)并再次启动时,第二个textvIEw为灰色.但是,一旦我旋转设备或下次启动应用程序,就会出现同样的问题.
问题设备正在运行4.1.1. – 在2.3.4设备上运行相同的应用程序没有问题.
SDK Tools 22.0.1,Eclipse Juno Service Release 2 32位
,windows 7 64位
编辑:SDK Tools 14上的相同问题,windows 7 32位上的Eclipse Indigo SR1 32位
我不知道那里发生了什么.这是某种不受欢迎的MAGIC.
请你帮助我好吗?
下面是真正的源代码,没有修改问题项目.
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>
编辑2:使事情更奇怪:如果我稍微改变textvIEw2的颜色,即#cdcdcd问题不会来.仅在两种颜色(textvIEw1和textvIEw2)在XML中相同的情况下.
解决方法 我找到了解决这个问题的方法 – 尽管不是解释.只有当xml中两个textvIEws的初始颜色相同时,才会出现此问题.因此,解决方案是为textvIEws提供不同的颜色.所以,如果你有同样的问题,这对我有用:
acitivity_main.xml:WITH问题
<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:没有问题
<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>
换句话说,我只使用了略微不同的颜色(实际上这里的透明度不同) – 问题就消失了.如果有人告诉我,我不相信.
总结以上是内存溢出为你收集整理的android – Textview无缘无故地改变背景颜色全部内容,希望文章能够帮你解决android – Textview无缘无故地改变背景颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)