Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Setting TextView to Bold Not Working

Here is the XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/modal_list_row"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:paddingBottom="7.5dp"     android:orientation="vertical" >      <TextView                 android:id="@+id/title_text_view"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_alignParentTop="true"                 android:layout_centerHorizontal="true"                 android:gravity="center"                 android:text="@string/alert_title_small"                 android:textColor="@color/alert_dialog_text_color"                 android:textSize="@dimen/alert_dialog_title_font_size"                 android:textStyle="bold" />  </RelativeLayout> 

Although the Graphical Layout shows bold text, on the device it's not. Is it a device thing or what?

Update:

For people who keeps on asking for the ful XML, here it is updated. A simple relative layout. And here is the Java Code:

this.titleTextView.setText(this.modalListState.title); 

Things to think about: Could it be due to the device typefaces? Does anyone have Galaxy S3 to confirm? Could it be the activity style? Here is the one used for the whole app:

<resources xmlns:android="http://schemas.android.com/apk/res/android">  <!--     Base application theme, dependent on API level. This theme is replaced     by AppBaseTheme from res/values-vXX/styles.xml on newer devices.  --> <style name="AppBaseTheme" parent="android:Theme.Light">     <!--         Theme customizations available in newer API levels can go in         res/values-vXX/styles.xml, while customizations related to         backward-compatibility can go here.      --> </style>  <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme">     <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style>  <style name="TransparentActivity" >     <item name="android:windowBackground">@android:color/transparent</item>     <item name="android:colorBackgroundCacheHint">@null</item>     <item name="android:windowIsTranslucent">true</item>     <item name="android:windowAnimationStyle">@android:style/Animation</item>     <item name="android:windowNoTitle">true</item>     <item name="android:windowContentOverlay">@null</item>     <item name="android:windowFullscreen">false</item> </style> 

The TransparentActivity style is used for the concerned activity.

like image 927
Abdalrahman Shatou Avatar asked Jun 07 '13 22:06

Abdalrahman Shatou


People also ask

How do I change TextView to bold?

Change Text Style of TextView to BOLD in XML Layout File textStyle attribute of TextView widget accepts on of these values: "bold" , "italic" or "normal" . To change the style to bold, you have to assign textStyle with "bold" .

How do you change text to bold on Android?

Add text to your message. Double tap the text you want to format. Tap Format, then choose a formatting option like bolding, italics, or changing the font color.

How do I make text bold in TextView android programmatically?

text. style. StyleSpan(Typeface. BOLD), start, end, Spannable.

How do I make a string bold in XML?

Just use getText(R. string.


2 Answers

Well, I found a silly answer to this problem. I was using a custom font on the device, not the default one. Once I switched to the default one, every things worked as expected!

like image 198
Abdalrahman Shatou Avatar answered Sep 30 '22 22:09

Abdalrahman Shatou


there is one method, you can set textview typeface by calling setTypeface method...

 textView.setTypeface(null, Typeface.BOLD_ITALIC);  textView.setTypeface(null, Typeface.BOLD);  textView.setTypeface(null, Typeface.ITALIC); 

and also refer this link...

Set TextView style (bold or italic)

like image 20
Nilesh Patel Avatar answered Sep 30 '22 22:09

Nilesh Patel