Skip to content

Instantly share code, notes, and snippets.

@bonnyfone
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonnyfone/4edabbe39927a363bfbe to your computer and use it in GitHub Desktop.
Save bonnyfone/4edabbe39927a363bfbe to your computer and use it in GitHub Desktop.
ShadowyTextView: stronger "shadow" effect on text
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.TextView;
/**
* Created by ziby on 13/04/15.
*/
public class ShadowyTextView extends TextView {
protected boolean superShadow;
public ShadowyTextView(Context context) {
super(context);
}
public ShadowyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ShadowyTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ShadowyTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onDraw(Canvas canvas) {
if(isSuperShadow()){
int textColor = getTextColors().getDefaultColor();
setTextColor(Color.DKGRAY); // your stroke's color
getPaint().setStrokeWidth(5);
getPaint().setStyle(Paint.Style.STROKE);
super.onDraw(canvas);
setTextColor(textColor);
getPaint().setStrokeWidth(0);
getPaint().setStyle(Paint.Style.FILL);
super.onDraw(canvas);
}
else{
super.onDraw(canvas);
}
}
public boolean isSuperShadow() {
return superShadow;
}
public void setSuperShadow(boolean superShadow) {
this.superShadow = superShadow;
invalidate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment