I write an application in Hebrew but there is a problem with the direction of the words:
This is the code:
textView2.setText("יצרן: " + company + "\n");
textView2.append("דגם: " + degem + "\n");
textView2.append("מנוע: " + manoa + "\n");
textView2.append("ק'מ/ליטר: "+ watt + "\n");
textView2.append("נסיעה: " + timeString + " " + timeMedida+"\n");
I got:
יצרן:ABARTH
instead of
ABARTH:יצרן
and
דגם:005
instead of
דגם:500
the xml:
<TextView
android:id="#+id/txt_1_delek"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50sp"
android:layout_marginRight="100sp"
android:layout_marginLeft="100sp"
android:text="myTextView"/>
In case someone stumbles upon this old question and is looking for an answer... Amir's link points toward the right direction.
What you need is to change the text's base direction (and not the alignment, so as explained in the link "gravity.RIGHT" wont help there). Inserting the "left mark" unicode character \u200F at the beginning of your string will do the trick.
BTW just adding it as a hardcoded character didn't work for me, apparently because of encoding issues. I prefered to avoid dealing with it in the code, so i simply extract the character as a string from strings.xml, let android do the conversion as it wishes, and append the string (in your case "יצרן: " + company + "\n") in realtime.
Related
I've seen few questions like this but I'm a beginner and cannot quite fix this while looking at other people's different problems. So, my problem is pretty simple actually, I just have a TextView in my RecyclerView, and whenever I want to press that Highlighted TextView I want it to open up a site that I direct it to, I guess something's missing in my MainActivity, but not sure what. Here's my xml code :
<TextView
android:id="#+id/shoptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:layout_marginEnd="60dp"
android:textColor="#color/black"
android:linksClickable="true"
android:autoLink="web"
android:textColorLink="#color/black"
android:text="#string/shop"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/myText2" />
Here's my MainActivity code :
shopText = findViewById(R.id.shoptext);
shopText.setMovementMethod(LinkMovementMethod.getInstance());
Thanks in advance.
try this may helps
TextView link = (TextView) findViewById(R.id.text_view_id);
String linkText = getString(R.string.acceop)
+ "<a href='https://www.dmaghi.com/eula/terms/terms.html'> " + getString(R.string.trms) + " </a>"
+ getString(R.string.acceop2)
+ "<a href='https://www.dmaghi.com/eula/policies/privacy/privacy.html'> " + getString(R.string.polces) + " </a>.";
link.setText(Html.fromHtml(linkText));
link.setMovementMethod(LinkMovementMethod.getInstance());
Consider this HTML:
<ul>
<li>Some bullet point text.</li>
<li>Another bullet point:</li>
<ul>
<li>A Sub Bullet point of the above.</li>
<ul>
<li>A Sub sub bullet point.</li>
</ul>
<li>The second sub bullet point.</li>
</ul>
</ul>
I'm loading this into a TextView in MainActivity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val someText = findViewById<TextView>(R.id.someTextView)
val url = "<ul>\n" +
" <li>Some bullet point text.</li>\n" +
" <li>Another bullet point:</li>\n" +
" <ul>\n" +
" <li>A Sub Bullet point of the above.</li>\n" +
" <ul>\n" +
" <li>A Sub sub bullet point.</li>\n" +
" </ul>\n" +
" <li>The second sub bullet point.</li>\n" +
" </ul>\n" +
"</ul>\n"
someText.text = Html.fromHtml(url, Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE)
}
Nothing special with the activity_main.xml:
<TextView
android:id="#+id/someTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expected (Sub, Sub-sub bullet points):
Actual (no sub and sub-sub bullets AND indenting is wrong):
I've tried this library but it has the same problems.
Another solution would be to convert the tags to "\u25CF" and sub-sub bullets to "\u25CB" (or BulletSpan) and use JSoup for the ordering. But this feels like a lot of work for a standard HTML text.
I've tried MyTagHandler but the same problem.
Any ideas?
Thanks for the help guys!
ul and li tags are not supported by Html.fromHtml() method. There is an open issue in Google Issue Tracker about these missing tag supports and about the supported tags not listen on Html.fromHtml() method's documentation.
But, I think BulletSpan might be helpful.
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
how do i create a multiline string in EditText?
i want to display a string in a multiline EditText. Currently, the string displays as....
Receive: 0 coin(s) Total
Cost: $100
I want want it to display as...
Receive: 0 coin(s)
Total Cost: $10
This is my code, I have tried to use "\n", but to no avail...
result.setText("Receive:"+ " "+ df.format(rawounces)+"coin(s)" + "\n"
+ "Total Cost:$" + df.format(transactionandpremium*rawounces));
Thank you in advance.
You can use the Html attribute to set text as you want as ::
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
String str="Receive: 0 coin(s) <br> Total Cost: $10";
editText.setText(Html.formHtml(str));
I want to tweet some text to Twitter using line breaks.
I've tried \n or \r like in my code below, but Twitter is ignoring those.
tweet.setText(" Text1 " + "\n" + "Text2");
Thanks in advance!
try <br /> or [br /].
<br /> is the standard html tag, sometimes websites and forums use [br /].
I can use Spannable in TextViews to create spans with different looks, underlines, strikethroughs and such. How can I do the same to alter line wrapping behavior? In particular, I don't want an email address to wrap in the middle, I want it to act like one word.
I tried WrapTogetherSpan, but I couldn't get it to work. It looks like it is only used by DynamicLayout, and I could not force the TextView to use DynamicLayout.
<TextView
android:id="#+id/merchant_email_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/account_setting_email"
android:gravity="center"
android:bufferType="spannable"
android:maxLines="2"
android:ellipsize="end"
/>
How I'm setting the spannable:
WrapTogetherSpan TOGETHER_SPAN = new WrapTogetherSpan() {};
String collectedString = getString(R.string.email_sentence, userEmail);
int emailOffset = collectedString.indexOf(userEmail);
Spannable emailSpannable = Spannable.Factory.getInstance()
.newSpannable(collectedString);
emailSpannable.setSpan(TOGETHER_SPAN, emailOffset,
emailOffset + userEmail.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(emailSpannable)
Don't know if you have found an answer to it but you can use unicode to help you out.
there is a non-break space character, so you will need to replace all the spaces you want to be unbreakable with this character (\u00A0)
for an example
String text = "Hello World";
text.replace(' ', '\u00A0');
textView.setText(text);
by the way I've looked for a span solution and couldn't find one, WrapTogetherSpan is just an interface so it wouldn't work...
but with this method I'm sure you could make a custom unbreakable span if you want.
If you are implementing a more low-level solution (ie, drawing your own text and handling line-wrapping yourself), then see BreakIterator. The BreakIterator.getLineInstance() factory method treats email addresses as a single unit.
String text = "My email is me#example.com.";
BreakIterator boundary = BreakIterator.getLineInstance();
boundary.setText(text);
int start = boundary.first();
for (int end = boundary.next(); end != BreakIterator.DONE; end = boundary.next()) {
System.out.println(start + " " + text.substring(start, end));
start = end;
}
The output shows the boundary start indexes where line breaks would be acceptable.
0 My
3 email
9 is
12 me#example.com.
See also
How does BreakIterator work in Android?
How is StaticLayout used in Android?
Have you tried adding android:singleLine="true" to your XML?