Android Tips, Techniques and Theory

PART 1: Creating Content with XML with Android Studio (No programming required)

With Simple Recipes


(Click Table of Content button to expand or collapse TOC)


EXECUTIVE SUMMARY

Most things you do in Android Studio require both a XML file and Java code. Also, most content can either be declared with XML or created with Java. So the concepts are broken into two separate parts. However, in production, you will typically use both XML and Java together.

For most XML attribute there is a corresponding Java method. See table below for some common examples using the TextView component. Notice that for each XML attribute, the corresponding Java method typically starts with a prefix of “set” as part of the method name.

XML Attribute Name

Related Java Method

Description

android:autoLink

setAutoLinkMask(int)

Set the controls whether links (e.g., urls, email) are automatically found and converted to clickable links.

android:cursorVisible

setCursorVisible(boolean)

Set the cursor visible (default) or invisible. 

android:ellipsize

setEllipsize(TextUtils. TruncateAt)

If set, causes words that are longer than the view is wide to be ellipsized

android:text

setText(CharSequence, TextView.BufferType)

Set the text to display

android:textAllCaps

setAllCaps(boolean)

Set the text in all caps 

android:textAppearance

setTextAppearance(int)

Set the base text color, typeface, size, and style

android:textColor

setTextColor(int)

Set the text color

android:textIsSelectable

isTextSelectable()

Indicates that the content of a non-editable text can be selected

android:textSize

setTextSize(int,float)

Set the size of the text

android:textStyle

setTypeface(Typeface)

Set the style (bold, italic) for the text

android:typeface

setTypeface(Typeface)

Set text’s typeface (e.g., normal, sans, serif, monospace) 

android:width

setWidth(int)

Set the width of the TextView.

As a beginner developer, you may want to start by creating and setting properties on most of your visible content with XML. As you become more proficient, you will want to migrate to create your content in Java code because the app will be faster and more efficient.