在两端对齐文本的TextView [英] Justify text in textview
问题描述
在我的应用程序首先我的TextView显示的文字。然后我想证明文本,但在Android中它不可能证明在TextView的文本。为了证明文本我从以帮助这个链接。我下面由@Kondzio,但它不工作提供了答案。我不知道什么是错在我的code。
In my app first I have textview to show text. Then I want to justify text but in android its not possible to justify text in textview. To justify text I am taking help from this link. I am following the answer provided by @Kondzio but its not working. I dont know whats wrong in my code.
code -
public class Benefits extends Activity{
private Button back;
LinearLayout bText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.benefits);
WebView view = new WebView(this);
view.setVerticalScrollBarEnabled(true);
((LinearLayout)findViewById(R.id.bText)).addView(view);
view.loadData(getString(R.string.benef), "text/html", "utf-8");
back.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
finish();
}
});
}
}
XML -
<LinearLayout
android:id="@+id/bText"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center">
</LinearLayout>
在strings.xml中 -
In strings.xml-
<string name="benef">
<![CDATA[
<html>
<head></head>
<body style="text-align:justify;color:gray;background-color:black;">
"1.some text\n
2.some text\n
.............
</body>
</html>
]]>
</string>
我设置scrollbarenabled为真,使垂直滚动在我的文字。
I am setting scrollbarenabled to true to make vertical scrolling on my text.
推荐答案
//将所有的语言内容使用HTML标签来证明。
// converting all the language content to justify using html tags.
String youtContentStr = String.valueOf(Html
.fromHtml("<![CDATA[<body style=\"text-align:justify;color:#222222; \">"
+ getResources().getString(R.string.passthe_content)
+ "</body>]]>"));
view.loadData(youtContentStr, "text/html", "utf-8");
编辑: 要么 改变你的code添加了回斜线
or change your code with added back slash
<body style=\"text-align:justify;color:gray;background-color:black;\">
这篇关于在两端对齐文本的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!