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 /].
Related
As you can see here, the phone number here is starting from the right to the left.
However, I want it to display it like this (Image here is edited):
This is the TextView displaying this message:
<TextView
android:text="#string/smsSentTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/smsSentTo"
android:textColor="#color/mdtp_white"
android:textSize="18sp"
android:layout_above="#+id/chooseUsernameAndPickProfilePicture"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"/>
#string/smsSentTo (Arabic locale): (looks like StackOverflow is displaying the {0} wrong, ignore that.)
<string name="smsSentTo">تم إرسال رسالة SMS إلى {0}</string>
#string/smsSentTo (English locale):
<string name="smsSentTo">An SMS has been sent to {0}</string>
As you can see, I'm formatting the text using MessageFormat:
String smsSentTo = MessageFormat.format(smsSentToTV.getText().toString(), phone);
smsSentToTV.setText(smsSentTo);
How can I get it to display these properly?
There is a solution with a downside
String html = "<p>تم إرسال رسالة SMS إلي</p>" + "+961 01 234 567";
textView.setText(Html.fromHtml(html));
The downside is that the HTML p tag prints a line afterwards separating the number into the next line. I tried to remove it with some HTML attributes or using tags other than p tag, but that didn't work
Hope this satisfies your need, or can give you even a clue.
I want to Show HTML code as Text in Tutorial App
String.xml
<string name="p1"><![CDATA[<html>\n<title> Font tag Example </title>\n<body>\n<font face="arial" size="1" color="blue"> WELCOME </font> <br>\n <font size="2" color="cyan"> WELCOME </font> <br>\n <pre>\n This text uses pre tag and preserves nextline and spaces\n </pre>\n </body>\n </html>]]></string>
prog1.xml
<TextView
android:id="#+id/p1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:textSize="18sp"
android:text="#string/p1" />
Show but without " ", Need Show with " " double quotation
require Show like this
to show double quote("") inside a textview use any of these
"
\"
here is the official android website
https://developer.android.com/guide/topics/resources/string-resource
Try it in your string.xml <string name="ffdfb">\"ffdfb\"</string>
or
<string name="ffdfb">"ffdfb"</string>
else try it in your xml android:text='"fvdfv"'
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.
static String test2 = " <h1> THis is the \n test </h1>";
TextView tst;
tst.setText(Html.fromHtml(test2));
Output: THis is the test
Required Output:
THis is the test
without replacing "\n" to "" is it possible??
There is an difference between \n and <br>.
"<br>" is the HTML Tag for a Line break while \n is the Unix Tag which will display a line break in the rendered source code but not in the rendered view in most cases.
\n will not work in HMTL, you should use <br> tag for new line in html
static String test2 = " <h1> THis is the <br> test </h1>";
you can do this in XML also by putting \n in double qoutes
make string resource
<string name="htmltext"><u><i>Project Title</i></u><u>Smart City Apps</u>+"\n"+Developed by Stack.</string>
android:text="#string/htmltext"/>
Xml response is like , but in one tag , the text is this:
<Description>
<center><strong><span>Warehouse / Building Maintenance</span></strong></center><br />
<br />
<strong><span>I</span></strong><span>mmediate openings available in the local Perris area for warehouse/building building maintenance positions. <br />
<br />
<strong>Job Description:</strong><br />
</span>
<ul>
<li><span>Associates will be responsible to define pieces of equipment that will paralyze operations if they fail, and plan whatever level of preventative maintenance necessary. <br />
</span></li>
<li><span>
......
similar text
......
</Description>
I can't able to parse it in proper way.
I tried using Jsoup.parse((nodeValue))
and Html.fromHtml(String) also URLEncoder.encode(String)
but its returning simple & symbol thats it.
How to parse this type of response?
A temporary solution could be applying replaceAll("<", "<").replaceAll(">", ">") if API methods aren't working, but arent you supposed to use Html.toHtml(string) when you have stuff encoded and want it to become real html ?
Actually its returning only & symbol , that's because the nodelist item returns only single value.
After using like this:
NodeList fstNm = fstNmElmnt.getChildNodes();
System.out.println("nodefstnm"+fstNm.getLength());
for(int j=0;j<fstNm.getLength();j++) {
String val = ((Node) fstNm.item(j)).getNodeValue();
nodeValue=nodeValue.concat(val);
}
and then parsing with Jsoup., returns what I want.