问题描述
我已经看到了IOS,你可以观察它在链接的意义RSMaskedLabel控制。我想在我的Android应用程序来实现这一点。我试着给(机器人:阿尔法=0),但其采取了透明的白盒子,但我想实现像在下面的图片。
I have seen the RSMaskedLabel control in ios as you can observe its significance in this link. I want to implement this in my android application. I tried giving (android:alpha="0") but its taking its transparent as white box,but I want to implement as like in the below picture.
有没有android的任何财产的TextView。
Is there any property for textView in android.
在Android的RSMasked标签属性。
RSMasked label property in android.
我没有找到关于android.I只是喜欢知道是否在android系统的任何属性为实现这一任务similiar性能在谷歌任何东西。
I didnt find anything in google regarding similiar properties in android.I just likes to know whether any properties in android for achieving this task.
请参阅图像和我张贴的链接。请建议我解决这个问题。
Please refer to the Image and the link which I posted. Please suggest me in solving this issue.
这是iOS中使用的code:
This is the code used in iOS:
#import "RSMaskedLabel.h"
@interface RSMaskedLabel()
- (void) RS_commonInit;
- (void) RS_drawBackgroundInRect:(CGRect)rect;
@end
@implementation RSMaskedLabel
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
[self RS_commonInit];
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if ((self = [super initWithCoder:aDecoder]))
[self RS_commonInit];
return self;
}
- (void)RS_commonInit
{
[super setTextColor:[UIColor whiteColor]];
[self setBackgroundColor:[UIColor clearColor]];
[self setOpaque:NO];
}
- (void)setTextColor:(UIColor *)textColor
{
// text color needs to be white for masking to work
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
// let the superclass draw the label normally
[super drawRect:rect];
CGContextConcatCTM(context, CGAffineTransformMake(1, 0, 0, -1, 0, CGRectGetHeight(rect)));
// create a mask from the normally rendered text
CGImageRef image = CGBitmapContextCreateImage(context);
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image), CGImageGetBytesPerRow(image), CGImageGetDataProvider(image), CGImageGetDecode(image), CGImageGetShouldInterpolate(image));
CFRelease(image); image = NULL;
// wipe the slate clean
CGContextClearRect(context, rect);
CGContextSaveGState(context);
CGContextClipToMask(context, rect, mask);
CFRelease(mask); mask = NULL;
[self RS_drawBackgroundInRect:rect];
CGContextRestoreGState(context);
}
- (void) RS_drawBackgroundInRect:(CGRect)rect
{
// this is where you do whatever fancy drawing you want to do!
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor whiteColor] set];
CGContextFillRect(context, rect);
}
@end
使用上述类,提示以下图像效果:
using the above class for getting the below image effect:
RSMaskedLabel *meLbl =[[RSMaskedLabel alloc]initWithFrame:CGRectMake(40.5,circle_view.frame.origin.y+circle_view.frame.size.height+27.5,239.5,51)]
[meLbl setTextAlignment:NSTextAlignmentCenter];
meLbl.font=[UIFont fontWithName:@"SourceSansPro-Bold" size:20];
meLbl.layer.opacity= 71.0f/100.0f;
meLbl.numberOfLines=2;
meLbl.layer.backgroundColor=[UIColor clearColor].CGColor;
meLbl.highlighted=YES;
[meLbl setText:popobj1.title];
请建议在Android的这一实施
Please suggest for implementing this in android.
在这里输入的形象描述
enter image description here
推荐答案
机器人:文字颜色=@机器人:彩色/ tranparent
如果使用的是XML布局
android:textColor="@android:color/tranparent"
if using the xml layout
或使用 textView.setTextColor(android.R.color.transparent);
我没有尝试过这一点,但如果你让你的TextView透明的(或者就像无背景)
I haven't tried this, but if you make your textView transparent (or just like having no background)
然后进行有跨度白色和,工作的?
and then make a span that has a BackgroundColorSpan of white and a ForegroundColorSpan of Transparent, does that work?
<TextView
android:id="@+id/awesometext"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
再后来就在code尝试是这样的:
Then later on in the code try something like this:
String text = "My Awesome text";
SpannableString spannable = SpannableString.valueOf(text);
spannable.setSpan(new BackgroundColorSpan(getColor(android.R.color.white)), 0, spannable.length() - 1, Spannable.INCLUSIVE_INCLUSIVE);
spannable.setSpan(new ForegroundColorSpan(getColor(android.R.color.transparent)), 0, spannable.length() - 1, Spannable.INCLUSIVE_INCLUSIVE);
textView.setText(spannable);
这篇关于如何实现为Android RSMasked Label属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!