Reputation: 2968
I am creating a Gallery application. Each image will show the title along with the name of the person who uploaded the image. Example of what I want is below:
Here the Night is dark, but this darkness has the silence is the title for the image, and the shaggy boy is the user who uploaded the image for example.
So, now I want Night is dark, but this darkness has the silence to be in the separate textview
and the shaggy boy at the end of the Night is dark, but this darkness has the silence's textview
even if Night is dark, but this darkness has the silence is a single line or multi-line.
I have used the Flexbox Layout
but I am failed to achieve what I want.
How to append the textview
to the end of another textview
?
Upvotes: 2
Views: 1404
Reputation: 40830
You can use a single TextView
with String palceholders of the quote and the author, and add the colors using HTML tags.
strings.xml
<resources>
<string name="tag">
<![CDATA[
<font color="#00000">%1$s</font> -
<font color="#D3D3D3">%2$s</font>
]]>
</string>
</resources>
Behavior:
String message = "Night is dark, but this darkness has the silence";
String name = "shaggy boy";
String formattedTag = String.format(getString(R.string.tag), message, name);
textview.setText(Html.fromHtml(formattedTag));
Upvotes: 0
Reputation: 40830
You can use a single TextView
and set its text String with a Spannable
and match each portion of text with indices here I am separating both portions by a hyphen; but you can change that as you would like.
TextView textView = findViewById(...);
String tag = "Night is dark, but this darkness has the silence - shaggy boy";
SpannableString spannableString = new SpannableString(tag);
spannableString.setSpan(new ForegroundColorSpan(Color.BLACK), 0, tag.indexOf("-"), 0);
spannableString.setSpan(new ForegroundColorSpan(Color.GRAY), tag.indexOf("-"), tag.length(), 0);
textView.setText(spannableString);
Upvotes: 1
Reputation: 464
Maybe you could just get the text of the author's TextView and add it to the String of the first TextView?
Upvotes: 0