Created
February 2, 2015 23:32
-
-
Save tokudu/61dbb99b84ee13b63287 to your computer and use it in GitHub Desktop.
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
int padding = 10; // in pixels | |
yourTextView.setShadowLayer(padding /* radius */, 0, 0, 0 /* transparent */); | |
yourTextView.setPadding(padding, padding, padding, padding); | |
// Now create the new span | |
String str = "Some really long string goes in here"; | |
Spannable spannable = new SpannableString(str); | |
spannable.setSpan(new PaddingBackgroundColorSpan( | |
getResources().getColor(android.R.color.black), | |
padding | |
), 0, str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
yourTextView.setText(spannable); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If padding is higher than 25, then add the following line before calling
setShadowLayer
:yourTextView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
This prevents a crash from occurring on older versions of Android: https://issuetracker.google.com/issues/37000500