PART 2: Creating Content with Java with Android Studio (Programming required)
With Simple Recipes
(Click Table of Content button to expand or collapse TOC)
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 |
---|---|---|
Set the controls whether links (e.g., urls, email) are automatically found and converted to clickable links. |
||
Set the cursor visible (default) or invisible. |
||
If set, causes words that are longer than the view is wide to be ellipsized |
||
Set the text to display |
||
Set the text in all caps |
||
Set the base text color, typeface, size, and style |
||
Set the text color |
||
Indicates that the content of a non-editable text can be selected |
||
Set the size of the text |
||
Set the style (bold, italic) for the text |
||
Set text’s typeface (e.g., normal, sans, serif, monospace) |
||
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.
How to read code:
EXAMPLE: Intent webIntent = new Intent();
Code: | Intent |
webIntent |
= |
new |
Intent() |
---|---|---|---|---|---|
Read: |
Create a new object of the data type Intent |
and name it webIntent |
by |
instantiating it with |
its constructor method |