Last active
August 29, 2015 14:19
-
-
Save bonnyfone/4edabbe39927a363bfbe to your computer and use it in GitHub Desktop.
ShadowyTextView: stronger "shadow" effect on text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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