title: Blur specific words in TextView
body: <p>I have an Android app, inside I have 3 TextViews in a vertical LinearLayout.  I want to blur parts of the TextViews by a String array containing the words that should be blurred. The TextViews looks like this.</p>
  
  <p><a href="https://i.stack.imgur.com/CTh8d.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CTh8d.jpg" alt="enter image description here"></a></p>
  
  <p>In this example, I want to blur all the occurrences of the words "than" and "third".</p>
  
  <p>I currently blur the text using a <code>BlurMaskFilter</code> like in <a href="https://stackoverflow.com/a/39313269/3731180">this answer</a>. However, it blurs the whole text in the TextView, and I want to blur specific words only.</p>
  
  <p>My solution was replacing the 3 TextViews by 3 horizontal LinearLayouts and loop through the text of the TextViews, when reaching a word that needs to be blurred, split the <code>TextView</code> to three TextViews: start, blurred part, end. In our example, it will be "this is the", "third"(blurred), "textview" for the third <code>TextView</code>.</p>
  
  <p>The problem I get can be seen here:  </p>
  
  <p><a href="https://i.stack.imgur.com/PuYhc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PuYhc.jpg" alt="enter image description here"></a></p>
  
  <p>So as you can see, when the text reaches more than one row, the second line won't start from the start of the screen, as it is a <code>LinearLayout</code> and the view before it takes some space. What I want to achieve is being able to cut a TextView in the middle of a line, even if it is a multiline TextView, add another TextView right next to it and blur it, and add the continuation of the text afterward, and it'll start the next line from the beginning. I don't know any layout type that will fit these needs, nor a way of achieving it in a different way.</p>
  
  <p>My current code to achieve the state shown in the last picture:</p>
  
  <p>Activity --> create the texts, and append them to the layouts:</p>
  
  <pre><code>LinearLayout linear0 = findViewById(R.id.testlinear0);
  LinearLayout linear1 = findViewById(R.id.testlinear1);
  LinearLayout linear2 = findViewById(R.id.testlinear2);
  
  TextView firstTextView = new TextView(this);
  firstTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
  setHtmlText(firstTextView, "adsada");
  firstTextView.setTextAppearance(this, R.style.WikiTextViewStyle);
  
  TextView aaa = new TextView(this);
  aaa.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
  setHtmlText(aaa, HelperClass.levelsContent.get(levelName)[0]);
  aaa.setTextAppearance(this, R.style.WikiTextViewStyle);
  
  TextView secondTextView = new TextView(this);
  secondTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
  setHtmlText(secondTextView, HelperClass.levelsContent.get(levelName)[1]);
  secondTextView.setTextAppearance(this, R.style.WikiTextViewStyle);
  
  TextView thirdTextView = new TextView(this);
  thirdTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
  setHtmlText(thirdTextView, HelperClass.levelsContent.get(levelName)[2]);
  thirdTextView.setTextAppearance(this, R.style.WikiTextViewStyle);
  
  
  thirdTextView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  float radius = thirdTextView.getTextSize() / 3;
  BlurMaskFilter filter = new BlurMaskFilter(radius, BlurMaskFilter.Blur.NORMAL);
  thirdTextView.getPaint().setMaskFilter(filter);
  
  linear0.addView(firstTextView);
  linear0.addView(aaa);
  linear1.addView(secondTextView);
  linear2.addView(thirdTextView);
  </code></pre>
  
  <p>layout --></p>
  
  <pre><code>&lt;LinearLayout
      android:id="@+id/imgLayout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@android:color/white"
      android:gravity="center"
      android:orientation="vertical"&gt;
  
      &lt;LinearLayout
          android:id="@+id/testlinear0"
          android:layout_width="match_parent"
          android:orientation="horizontal"
          android:layout_height="wrap_content"/&gt;
  
      &lt;LinearLayout
          android:id="@+id/testlinear1"
          android:layout_width="match_parent"
          android:orientation="horizontal"
          android:layout_height="wrap_content"/&gt;
  
      &lt;LinearLayout
          android:id="@+id/testlinear2"
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>