Monday, 24 July 2017

Create styling string from resources

Create styling string from resources


This example show how to create partial styling string from resources:


Edit values/strings.xml to add string resources with 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 use the string resources:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

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="http://android-er.blogspot.com/"
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 in 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>



download
alternative link download

Like the Post? Do share with your Friends.