Reputation: 61
How do I display my text in bold in the graphical layout of my xml? I would like my headings to be in bold, while the results are in normal format. Thank you. I hope you could help me with this matter.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/coordinates"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/instruction" />
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result" />
<Button
android:id="@+id/btn_process"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_text" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="300dp"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Original" />
<ImageView
android:id="@+id/imageSource"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/test_ideal_graph" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Result" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageAfter"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Upvotes: 2
Views: 2496
Reputation: 4013
In strings.xml
<string name="your_string_name"><b> I am bold text</b> And I am not bold</string>
Use this approach to get more flexibility in formatting text.
Also remember to use, Html.fromHtml("your html string");
to set text in the TextView
e.g.
String s="<b> I am text in bold </b> and I am not.";
TextView t=new TextView();
t.setText(Html.fromHtml(s));
Upvotes: 4
Reputation: 631
If you want all the text in the TextView
to be bold use,
android:textStyle="bold"
If you only want part of it to be bold, you could generate a Spannable
from Html using Html.fromHtml()
like this :
String text = "This is some <b>sample</b> text";
yourTextView.setText(Html.fromHtml(text));
Here "sample" would be in bold.
Upvotes: 2
Reputation: 13378
For example:
android:textStyle="bold"
or when italic is wanted:
android:textStyle="italic"
For more information:
http://developer.android.com/reference/android/text/style/package-summary.html
Also have look on this thread for more information:
How do you change text to bold in Android?
Upvotes: 2