Chapter 4
Chapter 4
TextView
• TextView displays text to the user and optionally
allows them to edit it programmatically.
• TextView is a complete text editor, however basic
class is configured to not allow editing but we can
edit it.
• <TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbhiAndroid" />
Attributes
• id: id is an attribute used to uniquely identify
a textview.
• <TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
• gravity:
• The gravity attribute is an optional attribute which
is used to control the alignment of the text like
left, right, center, top, bottom, center_vertical,
center_horizontal etc.
• <TextView android:id="@+id/simpleTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="AbhiAndroid"
android:textSize="20sp"
android:gravity="center_horizontal"/>
• text: text attribute is used to set the text in a text
view.
• <TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="25sp"
android:text="AbhiAndroid"/>
• textColor: textColor attribute is used to set the
text color of a text view. Color value is in the form
of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
• <TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbhiAndroid"
android:layout_centerInParent="true"
android:textSize="25sp"
android:textColor="#f00"/>
• textSize: textSize attribute is used to set the size of
text of a text view. We can set the text size in
sp(scale independent pixel) or dp(density pixel).
• <TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbhiAndroid"
android:layout_centerInParent="true"
android:textSize="40sp" />
• textStyle: textStyle attribute is used to set the
text style of a text view. The possible text styles
are bold, italic and normal. If we need to use two
or more styles for a text view then “|” operator is
used for that.
• <TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbhiAndroid"
android:layout_centerInParent="true"
android:textSize="40sp"
android:textStyle="bold|italic"/>
• background: background attribute is used to set
the background of a text view. We can set a color
or a drawable in the background of a text view.
• <EditText android:id="@+id/simpleEditText"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
Attributes of EditText
• id: id is an attribute used to uniquely identify a
text EditText.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType=“textpassword"/>
• <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="date"/>
ImageButton
• In Android, ImageButton is used to display a
normal button with a custom image in a button.
• In simple words we can say, ImageButton is
a button with an image that can be pressed or
clicked by the users.
• By default it looks like a normal button with the
standard button background that changes the
color during different button states.
• id: id is an attribute used to uniquely identify
a image button. Below is the example code in
which we set the id of a image button.
• <CheckBox
• android:id="@+id/aus"
• android:layout_width="wrap_content"
• android:layout_height="wrap_content"
• android:layout_marginLeft="20dp"
• android:layout_marginTop="10dp"
• android:checked="false"
• android:text="Australlia"
• android:textColor="#154"
• android:textSize="20sp"
• android:textStyle="bold" /></LinearLayout>
ProgressBar