K Roobroeck
K Roobroeck

Reputation: 1418

Set text in textview very blurry

I'm looking into methods of completely blurring a text in a textview. Read, completely unreadable (pixelate). The methods i'm using now are using shadows. But this seems very inefficient. Anyone who has a better solution?

Upvotes: 10

Views: 14182

Answers (4)

Ricard
Ricard

Reputation: 1293

If you are looking to obfuscate the text you can try using TransformationMethod of TextView.

Here you have an example, is not a blurring effect but may help: https://gist.github.com/RicardAparicio/bdd6cd30410f9431e1da238202a1dfa9

Upvotes: 0

theczechsensation
theczechsensation

Reputation: 4275

I did not like the Paint method used in the other answers. The below code is working for me with the radius calculated depending on the font size and applying it directly on the TextView.

if (Build.VERSION.SDK_INT >= 11) {
     yourTextView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
float radius = yourTextView.getTextSize() / 3;
BlurMaskFilter filter = new BlurMaskFilter(radius, BlurMaskFilter.Blur.NORMAL);
yourTextView.getPaint().setMaskFilter(filter);

Upvotes: 35

vmathieu
vmathieu

Reputation: 220

You should try to use canvas instead of TextView and draw a text with blur. There is a lot of method using BlurMaskFilter and you can use this like that :

paint.setMaskFilter(new BlurMaskFilter(float radius, BlurMaskFilter.Blur style));

Upvotes: 4

Gagan
Gagan

Reputation: 1497

You may try below methods:

  1. Whenever you want to show blurry text, use a specialized font for your TextView, added to asset folder of your project.
  2. Try setting a transparent color[#00ffffff] to your text and give some shadow to it.

I hope one of the above method helps.

Upvotes: 0

Related Questions