Android UI - Layouts, Colors, Styles, Themes
View
- The highest-level class of any UI in Android.
Button, TextView, and other UI elements inherit from it.- Can be added from code or in xml file
- All views are organized into a single tree
- View Group - container for other views
Button, TextView, and other UI elements inherit from it.Layout
- Defines the visual structure of the UI.
Layout Types
Constraint Layout
- Views are positioned relative to other widgetsCommon attributes
layout_width, layout_height: match_parent, wrap_content.
layout_width, layout_height: match_parent, wrap_content.Linear Layout
- Arranges child views in a single direction (either vertical or horizontal).
- Can be a child of
ConstraintLayout.
Relative Layout
- Widgets are arranged in relative positions to each other.
- Supports alignment options like bottom, center, left, right.
Table Layout
- Arranges child views in rows and columns.
- Consists of
TableRowelements.
Frame Layout
- Blocks out an area to display a single item.
Style
A set of attributes applied to a single
View.Attributes include color, font size, font color, background color, etc.
Defined in the
styles.xmlfile.Defined using the
<style>element inside a resource XML file.Basic Example (
res/values/styles.xml):
Theme
A set of attributes applied to the entire app.
A collection of multiple styles.
Located in
res/values/themes/.The default theme is in
themes.xml.Defined in XML files.
A single
themes.xmlfile can contain multiple themes.Example:
AndroidManifest.xml file within the <application> or <activity> tag using the android:theme attribute.An app can use multiple themes in different ways:
Different Themes for Different Activities
- You can assign different themes to different activities by specifying
android:themein each<activity>tag inAndroidManifest.xml. - Switch Themes Dynamically at Runtime
- Using DayNight Theme for Automatic Switching
styles.xml → For reusable component styles (buttons, text views, etc.).themes.xml → For app-wide themes.Colors
Colors are defined in
colors.xml.You can modify default colors for the app here.
The app has three default colors, but you can add custom colors later.
You can create multiple
colors.xmlfiles insideres/values/to keep colors organized.For example:
Default colors file (
res/values/colors.xml):Dark mode colors (
res/values-night/colors.xml):Custom colors file (
res/values/colors_brand.xml):
Comments
Post a Comment