Rana Maninder Singh
Lesson 6 of 8Android App Development

Styling for Mobile — Making It Look Like a Real App

Lesson opener

In one line: Safe areas - notch, status bar, home indicator.

Why it matters: This shows up at work when you need to safe areas - notch, status bar, home indicator.

Before this lesson: Number guessing game

Before you start

ResourceLink
PreviousNumber guessing game
NextTesting & debugging
Time~50 minutes

What you will learn

  • Safe areas — notch, status bar, home indicator
  • Responsive layout with Dimensions (not CSS media queries)
  • Platform-specific shadows and styles
  • Dark mode with useColorScheme
  • Loading and skeleton states

Same styling concepts apply on iOS — see ios2 for HIG-specific patterns.

Section 1 — Safe areas (critical gap)

Plain English: iPhones have a notch and home bar. Android has status bars and gesture navigation. Content placed edge-to-edge gets hidden. Stores reject apps that ignore this.

npx expo install react-native-safe-area-context
import { SafeAreaView } from 'react-native-safe-area-context';

export default function Screen() {
  return (
    <SafeAreaView style={{ flex: 1, backgroundColor: '#fff' }}>
      {/* Content stays below notch and above home indicator */}
    </SafeAreaView>
  );
}

Not using SafeAreaView is a fast path to "Design" rejection on iPhone X and newer. Wrap every full screen.

What breaks if ignored: Title and buttons clipped under the status bar; bottom buttons unreachable above the home gesture area.


Section 2 — Responsive design with Dimensions

Web devs use @media (max-width: 600px). React Native uses window size in JavaScript:

import { Dimensions, StyleSheet } from 'react-native';

const { width, height } = Dimensions.get('window');

const styles = StyleSheet.create({
  card: {
    width: width * 0.9,        // 90% of screen width
    maxWidth: 400,             // cap on tablets
    padding: width < 360 ? 12 : 20,  // tighter on small phones
  },
});

Use useWindowDimensions() hook when layout must update on rotation.


Section 3 — Platform-specific styles

Android uses elevation for shadows. iOS uses shadow* props. Same component, different look:

import { Platform, StyleSheet } from 'react-native';

const styles = StyleSheet.create({
  button: {
    backgroundColor: '#2563eb',
    borderRadius: 8,
    padding: 14,
    ...Platform.select({
      android: {
        elevation: 4,
      },
      ios: {
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 2 },
        shadowOpacity: 0.25,
        shadowRadius: 4,
      },
    }),
  },
});

Platform.OS === 'android' when you need conditional logic in JSX.


Section 4 — Dark mode

import { useColorScheme, StyleSheet } from 'react-native';

export default function ThemedScreen() {
  const scheme = useColorScheme(); // 'light' | 'dark' | null
  const isDark = scheme === 'dark';

  return (
    <View style={[styles.container, isDark && styles.containerDark]}>
      <Text style={[styles.text, isDark && styles.textDark]}>
        Respects system theme
      </Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, backgroundColor: '#ffffff' },
  containerDark: { backgroundColor: '#0f172a' },
  text: { color: '#1e293b' },
  textDark: { color: '#f1f5f9' },
});

Apply to your guessing game for portfolio polish.


Section 5 — Loading and skeleton states (minor gap)

Never show a blank screen while fetching:

import { ActivityIndicator, View, Text, StyleSheet } from 'react-native';

function Leaderboard({ loading, items }) {
  if (loading) {
    return (
      <View style={styles.center}>
        <ActivityIndicator size="large" color="#2563eb" />
        <Text style={styles.muted}>Loading scores…</Text>
      </View>
    );
  }
  if (items.length === 0) {
    return (
      <View style={styles.center}>
        <Text>No scores yet — play a round!</Text>
      </View>
    );
  }
  // ... FlatList
}

Skeleton: gray placeholder rectangles with opacity: 0.3 while data loads — same idea as web skeleton UIs.


Section 6 — Permissions reminder (critical gap)

Camera, location, and storage require declare + request. See android1. Style alone does not replace runtime permission dialogs — request before opening camera APIs.


Practice

Do this now: Wrap your game screens in SafeAreaView. Add dark mode background to Home. Add ActivityIndicator while getBestAttempts() loads on Home.

Checklist

  • [ ] SafeAreaView on all full screens
  • [ ] Platform.select for shadows
  • [ ] Dark mode tested in system settings
  • [ ] Loading state while AsyncStorage reads

What's next

Testing & debugging — find errors before users do.