Mada za sehemu hiiWorking with mobile apps and development platformsMada 4
- Setting up the development environment
- Performing exploration of basic mobile user interface components
- Using layouts, views, and containers
- Performing addition and customisation of basic user interface components
User Interface Components in Mobile Apps
A mobile app's user interface (UI) is what users see and interact with. Adding and customizing UI components like buttons and input fields makes an app both functional and visually appealing. In mobile development, we can add components using XML (declarative layout) or code (programmatic approach).
Mobile apps typically use these fundamental components:
- TextView – displays text to the user
- Button – a clickable element that triggers an action
- EditText – an input field where users type text
- ImageView – displays images
- CheckBox – allows multiple selections
Each component has properties (attributes) that control its appearance and behavior.
XML (eclamable Markup Language) defines the layout in a separate file. This approach separates design from code, making it easier to visualize and modify the interface.
Steps to add a button in XML:
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:textColor="#FFFFFF"
android:background="#2196F3" />
Key attributes:
android:id– unique identifier for the componentandroid:layout_widthandandroid:layout_height– size settingsandroid:text– displayed textandroid:textColor– text colorandroid:background– background color or drawable
Adding an input field:
<EditText
android:id="@+id/userNameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:inputType="textPersonName" />
Sometimes we need to create UI elements directly in code, especially when the interface must change based on user actions.
Adding a button programmatically:
Button myButton = new Button(this);
myButton.setText("Submit");
myButton.setId(View.generateViewId());
myButton.setBackgroundColor(Color.parseColor("#4CAF50"));
// Add to the layout
LinearLayout layout = findViewById(R.id.myLayout);
layout.addView(myButton);
Adding an input field programmatically:
EditText emailInput = new EditText(this);
emailInput.setHint("Enter email");
emailInput.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
Buttons can be customized to match app branding:
Changing background and text color:
<Button
android:background="@drawable/button_style"
android:textColor="#FFFFFF" />
Creating a custom button shape (XML drawable):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF5722" />
<corners android:radius="8dp" />
</shape>
Setting button dimensions:
android:minWidth="120dp"
android:minHeight="48dp"
android:padding="16dp"
Input fields (EditText) can be styled for better user experience:
Adding icons inside the input field:
<EditText
android:drawableStart="@drawable/ic_person"
android:drawablePadding="8dp" />
Setting input type constraints:
android:inputType="number" <!-- numbers only -->
android:inputType="textPassword" <!-- hidden characters -->
android:inputType="phone" <!-- phone number keyboard -->
Styling the input field border:
<EditText
android:background="@drawable/input_border"
android:padding="12dp" />
Good mobile apps are usable by everyone, including people with disabilities:
- Set meaningful
contentDescriptionfor images - Ensure adequate color contrast between text and background
- Make touch targets at least 48dp × 48dp
- Support screen readers by providing clear labels
Let's create a simple login screen layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome Back"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginBottom="16dp" />
<EditText
android:id="@+id/emailInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email address"
android:inputType="textEmailAddress"
android:layout_marginBottom="12dp" />
<EditText
android:id="@+id/passwordInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:layout_marginBottom="24dp" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:background="#2196F3"
android:textColor="#FFFFFF" />
</LinearLayout>
This creates a vertical layout with a title, two input fields (email and password), and a login button.
In Tanzania, mobile apps for small businesses like M-Pesa agents or market vendors use customized UI components to create user-friendly interfaces. For example, a Tanzanian shop owner building a simple inventory app would add buttons for "Add Sale," "View Stock," and "Record Expense" — customizing each with clear text and distinct colors so staff with basic phone experience can easily tap the right button during busy market hours at Kariakoo or along the roadside stalls in Dar es Salaam.
Jinsi utakavyotathminiwaTathmini ya mchakato · Tathmini ya matokeo · Tathmini ya maarifa
Tathmini ya mchakato
- Add components to an app.
- Customize styles and interactions (e.g., button, color themes).
Tathmini ya matokeo
Mobile app with interactive and visually appealing UI elements.
Tathmini ya maarifa
Detailed knowledge of:
Method used: The student should explain
- styling and theming in mobile apps.
Principles: The student should explain the principles of:
- consistency in design and platform guidelines.
Theories: The student should explain:
- state management and component customization.
Circumstantial knowledge:
Detailed knowledge about:
- handling touch events, animations, and cross-platform compatibility of customized components.
Swali
Which UI component in Android is used to display text that the user can read but not edit?
Ingia ili kuwasilisha jibu lako na lihesabiwe katika umahiri wako.
Ingia ili kufanya mazoeziMwalimu
Umekwama? Niulize chochote kuhusu mada hii.
Ingia ili kumuuliza Mwalimu wa AI wa Sonza kuhusu swali hili.
Ingia ili kuulizaMajadiliano
Hakuna maswali bado