Is there a way to hide some (but not all) of the text in a TextView? I tried setting the size to 0 with AbsoluteSizeSpan, but that doesn\'t have any visual effect that I see.
I've figured out a way. Let's use SpannableString and Color.TRANSPARENT
For example: <> Original text : "Hello dude"
<> Expected text : "_____ dude"
val spannableString = SpannableString("Hello dude")
spannableString.setSpan(ForegroundColorSpan(Color.TRANSPARENT), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
yourTextView.text = spannableString
I just had this problem and wrote the following class:
public class NoDisplaySpan extends ReplacementSpan {
public NoDisplaySpan() {}
@Override
public void draw(Canvas arg0, CharSequence arg1, int arg2, int arg3,
float arg4, int arg5, int arg6, int arg7, Paint arg8) {}
@Override
public int getSize(Paint paint, CharSequence text, int start, int end,
FontMetricsInt fm) {
return 0;
}
}
It seems to only work within a paragraph; I get an ArrayIndexOutofBoundsException thrown when I set the span to extend past a newline. I'd love to hear if anyone can figure that out.
just had this issue. Basically you just display a part of the string by using substring or whatever and if you click on the textview, you set the fulltext to it.
Hope it can help out someone going through that topic. (Can copy paste a snipet of code if required).
Not sure if you are still looking for an answer to this, as it is very old, but I found it while looking for something and thought I could help. Have you tried setting one button on the keyboard or a hardware button to switch between the visible TextView and a hidden one. You would have to play around with copying text from visible to hidden if you want to keep the visible as part of the hidden. If you want the hidden to be its own text, then this will be an easy solution.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="0sp"
android:textColor="@android:color/transparent" />
Transparent text color hides the visibility of the text. Add textSize to that to remove or minimize the space it takes up.
try by this code:
I have complete by this code..
<TextView
android:id="@+id/tvi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
or
android:visibility="gone"
/>
or by code:-
TextView txtView = (TextView)findViewById(R.id.tvi);
txtView.setVisibility(View.INVISIBLE);
OR
txtView.setVisibility(View.GONE);
May be this will help you