Используем для текста HTML оформление
| Главная » Используем для текста HTML оформление | |
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv"
android:text="Пример текста"/>
</LinearLayout>
<string name="info"><![CDATA[
<font color="#4713f2"><b><i>HTML</b></font> - язык гипертекстовой разметки
</i><br></br>]]>
</string>
<![CDATA[ помещаем сюда html-код ]]>
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Объявляем объект TextView и привязываем к нашему элементу:
TextView Htext = (TextView) findViewById(R.id.tv);
//Создаем строковый ресурс и задаем ему значение с нашей строки "example":
String infoText = getResources().getString(R.string.example);
//Настраиваем строке HTML текст:
Htext.setText(Html.fromHtml(infoText));
}
}
| |
