Create Styling String From Resources

Posted on

This event present how to utilization partial styling string from resources:

Edit values/strings.xml to add together string resources amongst styling:

<resources>     <string name="app_name">AndroidStylingStringResources</string>     <string name="normal_name">It is Normal String</string>     <string name="italic_name">Partial <i>Italic String</i> from resources</string>     <string name="bold_name">Partial <b>Bold String</b> from resources</string>     <string name="underline_name">Partial <u>Underline String</u> from resources</string> </resources>  

Edit layout/activity_main.xml to role the string resources:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:padding="16dp"     android:orientation="vertical"     tools:context="com.blogspot.android_er.androidstylingstringresources.MainActivity">      <TextView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margin="20dp"         android:layout_gravity="center_horizontal"         android:autoLink="web"         android:text="https://rootandroid.org//"         android:textStyle="bold"/>     <TextView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textSize="28dp"         android:text="@string/normal_name"/>     <TextView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textSize="28dp"         android:textStyle="italic"         android:text="Whole TextView inwards italic style"/>     <TextView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textSize="28dp"         android:text="@string/italic_name"/>     <TextView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textSize="28dp"         android:text="@string/bold_name"/>     <TextView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textSize="28dp"         android:text="@string/underline_name"/>  </LinearLayout>