Android UI Lecture Basic Widgets
Android UI Lecture Basic Widgets
Android UI Lecture Basic Widgets
Android
USER INTERFACES
TextView
TextViews are
typically used to
display a caption.
<TextView
android:id="@+id/myTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000ff"
android:padding="3dp"
android:text="Enter User Name"
android:textSize="16sp"
android:textStyle="bold"
android:gravity="center">
</TextView>
ImageView
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android"
/>
Button and ImageButton
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"
... />
Button (Creating only with Image)
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_icon"
... />
Button (Creating text Image)
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:drawableLeft="@drawable/button_icon"
... />
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Activated"
android:textOff="Disabled"/>
EditText
Touching a text field places the cursor and automatically displays the
keyboard.
<EditText
android:id="@+id/txtUserName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:hint="Name">
</EditText>
• Sp (Scale-independent Pixels)
– Used for specifying font size
– Like the dp unit, but it is also scaled by the
user's font size preference.
– It is used so that the font size ca be adjusted
for both the screen density and user's
preference.
EditText- Specifying a Keyboard Type
<EditText
android:id="@+id/email_address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/email_hint"
android:inputType="textEmailAddress" />