我在一个 Activity 中有两个 TextView ,由 xml 定义 - 两者的背景颜色都是灰色。在我的应用程序中,我将其中一种 TextView 背景颜色设置为蓝色。这按预期工作。
但是:当我转动设备(旋转)或离开应用程序并再次返回时,另一个 TextView 也是蓝色的 - 故意与一组颜色相同...!?
当我离开应用程序并再次启动它时,第二个 TextView 保持蓝色。当我停止应用程序运行(终止)并再次启动它时,第二个 TextView 是灰色的。但是当我下次旋转设备或启动应用程序时,同样的问题出现了。
问题设备正在运行 4.1.1。 - 相同的应用程序在 2.3.4 设备上运行没有问题。
SDK 工具 22.0.1,Eclipse Juno Service Release 2 32 位 , Windows 7 64 位
编辑: SDK Tools 14、Windows 7 32 位 Eclipse Indigo SR1 32 位上的相同问题
我不知道那里发生了什么。这是某种不受欢迎的魔法。 你能帮帮我吗?
下面是问题项目没有修改的真实源代码。
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 中两个 TextView 的初始颜色相同时才存在此问题。因此,解决方案是为 TextView 提供不同的颜色。
所以,如果你有同样的问题,这对我有用:
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>
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无缘无故改变背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17720868/
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我有一张背景图片,我想在其中添加一个文本框。我想弄清楚如何将标题放置在其顶部的正确位置。(我使用标题是因为我需要自动换行功能)。现在,我只能让文本显示在左上角,但我需要能够手动定位它的开始位置。require'RMagick'require'Pry'includeMagicktext="Loremipsumdolorsitamet"img=ImageList.new('template001.jpg')img 最佳答案 这是使用convert的ImageMagick命令行的答案。如果你想在Rmagick中使用这个方法,你必须自己移植
如何使用Ruby的默认Curses库获取颜色?所以像这样:puts"\e[0m\e[30;47mtest\e[0m"效果很好。在浅灰色背景上呈现漂亮的黑色。但是这个:#!/usr/bin/envrubyrequire'curses'Curses.noecho#donotshowtypedkeysCurses.init_screenCurses.stdscr.keypad(true)#enablearrowkeys(forpageup/down)Curses.stdscr.nodelay=1Curses.clearCurses.setpos(0,0)Curses.addstr"Hello
状态:我正在构建一个应用程序,其中需要一个可供用户选择颜色的字段,该字段将包含RGB颜色代码字符串。我已经测试了一个看起来很漂亮但效果不佳的。它是“挑剔的颜色”,并托管在此存储库中:https://github.com/Astorsoft/picky-color.在这里我打开一个关于它的一些问题的问题。问题:请建议我在Rails3应用程序中使用一些颜色选择器。 最佳答案 也许页面上的列表jQueryUIDevelopment:ColorPicker为您提供开箱即用的产品。原因是jQuery现在包含在Rails3应用程序中,因此使用基
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我有以下内容:text.gsub(/(lower)(upper)/,'\1\2')我可以将\2替换为大写吗?类似于:sed-e's/\(abc\)/\U\1/'这在Ruby中可行吗? 最佳答案 查看gsub文档:str.gsub(模式){|匹配|block}→new_str在block形式中,当前匹配字符串作为参数传入,$1、$2、$`、$&、$'等变量将被适当设置。block返回的值将替换为每次调用的匹配项。"alowerupperb".gsub(/(lower)(upper)/){|s|$1+""+$2.upcase}
我想要像“嘿那里”这样的东西变成,例如,#316583。我希望将任意长度的字符串“归结”为十六进制颜色。我不知道从哪里开始。我在想,每个字符串的MD5散列都是不同的-但如何将该散列转换为十六进制颜色数字? 最佳答案 你可以只取几位前几位:require'digest/md5'color=Digest::MD5.hexdigest('Mytext')[0..5] 关于ruby-如何使用Ruby基于字母数字字符串生成颜色?,我们在StackOverflow上找到一个类似的问题:
我正在运行Puma2.8.2服务器来stub我的一些后端服务。有时Puma服务器会无缘无故地死掉。error.log中没有错误,下面是access.log的摘录:10.210.140.21--[15/Oct/201409:28:22]"GET/statusHTTP/1.1"200-0.0030-Gracefullystopping,waitingforrequeststofinish-Goodbye!===pumastartup:2014-10-1509:28:24+0100===10.210.140.21--[15/Oct/201409:28:24]"GET/statusHTTP/1
我在View中有这段代码prawn_document(:page_size=>"A4",:top_margin=>80,:bottom_margin=>40,:background=>"public/uploads/1.png")do|pdf|creation_date=Time.now.strftime('%d-%m-%Y')posts=@posts.eachdo|post|pdf.pad(10)dopdf.textpost.titlepdf.textpost.textendendpdf.page_count.timesdo|i|pdf.go_to_page(i+1)pdf.draw