为什么textView.setTextColor()仅支持10个字符的颜色名称?

时间:2017-08-03 16:41:54

标签: java android

例如,

TextView feedback = (TextView) findViewById(R.id.feedback);
        feedback.setText("good job!");
        feedback.setTextColor(0xff77dd77);

将文本颜色设置为#77dd77,我在此网站上找到了该颜色: http://www.colorhexa.com/77dd77

提前致谢!

1 个答案:

答案 0 :(得分:2)

根据setTextColor(int)的文件:

  

0xAARRGGBB形式的颜色值。

其中AA - 是alpha通道, [lastImageAsset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) { NSURL *imageURL = contentEditingInput.fullSizeImageURL; CIImage *inputImage = [CIImage imageWithContentsOfURL:imageURL]; inputImage = [inputImage imageByApplyingOrientation:contentEditingInput.fullSizeImageOrientation]; EAGLContext *glContext = [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES2]; CIContext *context = [CIContext contextWithEAGLContext:glContext]; CGImageRef imageRef = [context createCGImage:inputImage fromRect:inputImage.extent]; UIImage *image = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:UIImageOrientationUp]; NSData *imageData = UIImageJPEGRepresentation(image, 1.0); PHContentEditingOutput *output = [[PHContentEditingOutput alloc]initWithContentEditingInput:contentEditingInput]; PHAdjustmentData *adjustmentData = [[PHAdjustmentData alloc]initWithFormatIdentifier:@"Some Identifier" formatVersion:@"1.0" data:[@"Changed Something" dataUsingEncoding:NSUTF8StringEncoding]]; [output setAdjustmentData:adjustmentData]; [imageData writeToURL:output.renderedContentURL atomically:YES]; [[PHPhotoLibrary sharedPhotoLibrary]performChanges:^{ PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest changeRequestForAsset:lastImageAsset]; changeRequest.contentEditingOutput = output; } completionHandler:^(BOOL success, NSError * _Nullable error) { NSLog(@"%@, %i", error, success); }]; }]; 代表十六进制表示。所以0x的{​​{1}}部分是RGB 但是如果你尝试传递0xff77dd77它实际上是77DD77,颜色将完全不可见。