themes & styles - android mubasher

19
Android Themes & Styles By Mohammed Ersan

Upload: mohammed-ersan

Post on 21-Jan-2017

33 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Themes & Styles - Android Mubasher

Android Themes &

StylesBy Mohammed Ersan

Page 2: Themes & Styles - Android Mubasher

Who Am I?Mohammed Ersan

Senior Android Developer

MTT Dublin

Github @MoshDev

Page 3: Themes & Styles - Android Mubasher

Themes & Styles

Page 4: Themes & Styles - Android Mubasher

Themes & Styles

Style vs Theme

Style Basics

Inheritance

Attributes

View Constructors

Material

Theme Shared Styles

In-Layout Theme

ContextThemeWrapper

Selectors & Drawables

Hints & Tools

Page 5: Themes & Styles - Android Mubasher

Style

A style is a collection of properties that specify the look and format for a View or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.

Theme

A theme is a style applied to an entire Activity or application, rather than an individual View. When a style is applied as a theme, every View in the Activity or application will apply each style property that it supports.

Style vs Theme

Source: https://developer.android.com/guide/topics/ui/themes.html

Page 6: Themes & Styles - Android Mubasher

Style Theme

Style vs Theme

Page 7: Themes & Styles - Android Mubasher

Xml file

res/values

Root node <resources>

<style>

Name is required

<item>

Parent is Optional

AAPT (Android Asset Packaging Tool)

Style Basics

Source: https://developer.android.com/guide/topics/ui/themes.htmlhttp://elinux.org/Android_aapt

Page 8: Themes & Styles - Android Mubasher

Parent

<style name="MyButtonStyle" parent="@style/Widget.AppCompat.Button">

Period (dot)

only works for styles defined by your own resources

<style name="style_vs_theme_body_text.sample">

Period + Parent

<style name="style_vs_theme_body_text.sample" parent="Widget.AppCompat.Button">

Period + Parent =””

<style name="style_vs_theme_body_text.sample" parent="">

Inheritance

Page 9: Themes & Styles - Android Mubasher

● Format

○ Enum (only integers)

○ Boolean (true|false)

○ Color

○ Dimension

○ Flag (only integers)

○ Float

○ Fraction (only percentage %)

○ Integer

○ Reference (@)

○ String

● Pipe operator | OR

● Within attribute enums

Attributes (Properties)● Declare-styleable

○ R.styleable.<name>

○ R.styleable.<name>_<attribute>

Page 10: Themes & Styles - Android Mubasher

View(Context)

View(Context, AttributeSet) **

View(Context, AttributeSet, defStyleAttr)

View(Context, AttributeSet, defStyleAttr, defStyleRes) (Api 21)

View Constructors

Page 11: Themes & Styles - Android Mubasher

1. colorPrimary2. colorPrimaryDark3. colorControlNormal4. colorControlActivated5. colorButtonNormal6. textColorPrimary7. textColorSecondary8. textColorPrimaryDisableOnly9. textColorTertiary10.textColorHint11.windowBackground

Material

Page 12: Themes & Styles - Android Mubasher

toolbarStyle

buttonStyle

textViewStyle

checkboxStyle

Theme Default StylesTo change default view style

Check the <View> source code

Search Platform/AppCompat theme source code

Override the attribute value in your theme

Page 13: Themes & Styles - Android Mubasher

In-Layout Themeandroid:theme

Individual views

ViewGroup Inheritance

ContextThemeWrapperTextView1 --> ...InLayoutThemeActivity@7d3740eTextView2 --> android.view.ContextThemeWrapper@5c46c40TextView3 --> android.view.ContextThemeWrapper@b0afcbeTextView4 --> android.view.ContextThemeWrapper@b0afcbe

Page 14: Themes & Styles - Android Mubasher

ContextThemeWrapper

Page 15: Themes & Styles - Android Mubasher

Selectors & Drawables

Page 16: Themes & Styles - Android Mubasher

Hints & ToolsAlpha colors

Page 17: Themes & Styles - Android Mubasher

Hints & ToolsExtract Style

Page 18: Themes & Styles - Android Mubasher

ConclusionThemes are very powerful tool in Android, start using them correctly since the beginning of development and it will end well.

Page 19: Themes & Styles - Android Mubasher

Questions

つづく