Date post: | 21-Jan-2017 |
Category: |
Software |
Upload: | mohammed-ersan |
View: | 33 times |
Download: | 1 times |
Android Themes &
StylesBy Mohammed Ersan
Who Am I?Mohammed Ersan
Senior Android Developer
MTT Dublin
Github @MoshDev
Themes & Styles
Themes & Styles
Style vs Theme
Style Basics
Inheritance
Attributes
View Constructors
Material
Theme Shared Styles
In-Layout Theme
ContextThemeWrapper
Selectors & Drawables
Hints & Tools
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
Style Theme
Style vs Theme
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
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
● 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>
View(Context)
View(Context, AttributeSet) **
View(Context, AttributeSet, defStyleAttr)
View(Context, AttributeSet, defStyleAttr, defStyleRes) (Api 21)
View Constructors
1. colorPrimary2. colorPrimaryDark3. colorControlNormal4. colorControlActivated5. colorButtonNormal6. textColorPrimary7. textColorSecondary8. textColorPrimaryDisableOnly9. textColorTertiary10.textColorHint11.windowBackground
Material
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
In-Layout Themeandroid:theme
Individual views
ViewGroup Inheritance
ContextThemeWrapperTextView1 --> ...InLayoutThemeActivity@7d3740eTextView2 --> android.view.ContextThemeWrapper@5c46c40TextView3 --> android.view.ContextThemeWrapper@b0afcbeTextView4 --> android.view.ContextThemeWrapper@b0afcbe
ContextThemeWrapper
Selectors & Drawables
Hints & ToolsAlpha colors
Hints & ToolsExtract Style
ConclusionThemes are very powerful tool in Android, start using them correctly since the beginning of development and it will end well.
Questions
つづく