Share
Embed
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
90 slides
-
Styles A set of key-values pairs where the key is
a View attribute -
Styles A set of key-values pairs where the key is
a View attribute Speci c to a single view -
Styles A set of key-values pairs where the key is
a View attribute Speci c to a single view Can't be changed once applied -
Styles <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:insetBottom="0dp" android:insetTop="0dp" android:text="Hello"/> <com.google.android.material.button.MaterialButton android:layout_width="100dp" android:layout_height="wrap_content"
android:insetBottom="0dp" android:insetTop="0dp" android:text="Make Payment"/> -
Styles <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:insetBottom="0dp" android:insetTop="0dp" android:text="Hello"/> <com.google.android.material.button.MaterialButton android:layout_width="100dp" android:layout_height="wrap_content"
android:insetBottom="0dp" android:insetTop="0dp" android:text="Make Payment"/> -
Styles <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:insetBottom="0dp" android:insetTop="0dp" android:text="Hello"/> <com.google.android.material.button.MaterialButton android:layout_width="100dp" android:layout_height="wrap_content"
android:insetBottom="0dp" android:insetTop="0dp" android:text="Make Payment"/> <style name="ButtonStyle" parent="Widget.MaterialComponents.Button"> <item name="android:insetTop">0dp</item> <item name="android:insetBottom">0dp</item> </style> -
Styles <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/ButtonStyle" android:text="Hello"/> <com.google.android.material.button.MaterialButton android:layout_width="100dp" android:layout_height="wrap_content" style="@style/ButtonStyle"
android:text="Make Payment"/> <style name="ButtonStyle" parent="Widget.MaterialComponents.Button"> <item name="android:insetTop">0dp</item> <item name="android:insetBottom">0dp</item> </style> -
TextAppearance A set of key-values pairs speci c to TextView
or it's subclasses. -
TextAppearance A set of key-values pairs speci c to TextView
or it's subclasses. Can include only character level styling -
TextAppearance A set of key-values pairs speci c to TextView
or it's subclasses. Can include only character level styling Can be changed once applied -
TextAppearance <style name="RedTextH2"> <item name="android:textColor">#FF0000</item> <item name="android:textSize">18sp</item> </style> <TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="BlrDroid" android:textAppearance="@style/RedTextH2"/> -
Theme A set of key-values pairs where the key is
a Theme attribute -
Theme A set of key-values pairs where the key is
a Theme attribute Applies to a view hierarchy -
Theme A set of key-values pairs where the key is
a Theme attribute Applies to a view hierarchy Can't be changed once applied -
Theme <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:theme="@style/Theme.BlrDroidThemes" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"> <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorSurface">@color/colorSurface</item> <item name="colorOnSurface">@color/colorOnSurface</item> </style> -
ThemeOverlay * <p>For filled buttons, this class uses your theme's
{@code ?attr/colorPrimary} for the background * tint color and {@code ?attr/colorOnPrimary} for the text color. For unfilled buttons, this class * uses {@code ?attr/colorPrimary} for the text color and transparent for the background tint. MaterialButton.java -
ThemeOverlay <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:background="#FF0000" android:theme="@style/ThemeOverlay.RedPrimary" /> <style
name="ThemeOverlay.RedPrimary" parent=""> <item name="colorPrimary">#D80943</item> </style> -
ThemeOverlay <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:background="#FF0000" android:theme="@style/ThemeOverlay.RedPrimary" /> <style
name="ThemeOverlay.RedPrimary" parent=""> <item name="colorPrimary">#D80943</item> </style> -
App Level Styling <style name="ButtonStyle" parent="Widget.MaterialComponents.Button"> <item name="android:insetTop">0dp</item> <item name="android:insetBottom">0dp</item>
</style> <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" style="@style/ButtonStyle" android:layout_gravity="center_horizontal" /> -
App Level Styling <style name="Theme.BlrDroidThemes" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <item name="colorPrimary">@color/purple_500</item> <item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item> <item name="materialButtonStyle">@style/ButtonStyle</item> </style> -
App Level Styling <style name="Theme.BlrDroidThemes" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <item name="colorPrimary">@color/purple_500</item> <item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item> <item name="materialButtonStyle">@style/ButtonStyle</item> </style> <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:layout_gravity="center_horizontal" /> -
Context Matters A context will be tied to a theme
This theme can be different from the Activity/App theme -
Context Matters <com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!"/> <LinearLayout android:id="@+id/linear_layout" android:theme="@style/ThemeOverlay.RedPrimary">
<com.google.android.material.button.MaterialButton android:text="Hello"/> </LinearLayout> -
Context Matters val contextThemeWrapper = ContextThemeWrapper( this, R.style.ThemeOverlay_RedPrimary ) val
materialButton = MaterialButton(contextThemeWrapper) materialButton.text = "World" binding.linearLayout.addView(materialButton) Option - 1 -
Context Matters public MaterialButton(@NonNull Context context, @Nullable AttributeSet attrs, int
defStyleAttr) { super(wrap(context, attrs, defStyleAttr, DEF_STYLE_RES), attrs, defStyleAttr); // Ensure we are using the correctly themed context rather than the context that was passed in. context = getContext(); } MaterilButton.java -
Context Matters public static Context wrap(//params ) { int materialThemeOverlayId
= obtainMaterialThemeOverlayId(context, attrs, defStyleAttr, defStyleRes); boolean contextHasOverlay = context instanceof ContextThemeWrapper && ((ContextThemeWrapper) context).getThemeResId() == materialThemeOverlayId; //.. Context contextThemeWrapper = new ContextThemeWrapper(context, materialThemeOverlayId); // .. return contextThemeWrapper; } MaterialButton.java -
Context Matters <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <com.google.android.material.button.MaterialButton
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> </LinearLayout> -
Context Matters <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <com.google.android.material.button.MaterialButton
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> </LinearLayout> -
Custom View Styling class ProgressButton @JvmOverloads constructor( context: Context, attrs:
AttributeSet? = null, defStyleAttr: Int = 0 ) : View(context, attrs, defStyleAttr) -
Custom View Styling class ProgressButton @JvmOverloads constructor( context: Context, attrs:
AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 ) : View(context, attrs, defStyleAttr, defStyleRes) { -
Custom View Styling class ProgressButton @JvmOverloads constructor( context: Context, attrs:
AttributeSet? = null, defStyleAttr: Int = R.attr.progressButtonStyle, defStyleRes: Int = R.style.ProgressButtonStyle ) : View(context, attrs, defStyleAttr, defStyleRes) { -
Custom View Styling class ProgressButton @JvmOverloads constructor( context: Context, attrs:
AttributeSet? = null, defStyleAttr: Int = R.attr.progressButtonStyle, defStyleRes: Int = R.style.ProgressButtonStyle ) : View(context, attrs, defStyleAttr, defStyleRes) { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ProgressButton, defStyleAttr, defStyleRes) -
Custom View Styling defStyleRes <style name="ProgressButtonStyle"> <item name="progressButton_backgroundColor">?attr/colorPrimary</item> <item name="progressButton_textColor">?attr/colorOnPrimary</item>
<item name="progressButton_progressColor">?attr/colorOnPrimary</item> </style> -
Custom View Styling <resources> <attr name="progressButtonStyle" format="reference"/> </resources> defStyleAttr <style
name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="progressButtonStyle">@style/ProgressButtonStyle</item> </style> -
Color Theming <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"> <item name="colorPrimary">#006837</item> <item name="colorPrimaryDark">#004012</item> <item
name="android:colorBackground">#FFFFFF</item> </style> -
Color Theming <color name="white">#FFFFFF</color> <color name="blue">#0F6BDD</color> <color name="blueDark">#0C52A8</color> <style name="AppTheme"
parent="Theme.MaterialComponents.DayNight.NoActionBar"> <item name="colorPrimary">@color/blue</item> <item name="colorPrimaryDark">@color/blueDark</item> <item name="android:colorBackground">@color/white</item> </style> -
Color Theming - Dark Mode? <color name="white">#FFFFFF</color> <color name="blue">#0F6BDD</color> <color
name="blueDark">#0C52A8</color> values-night/colors.xml -
Color Theming - Dark Mode? <color name="colorPrimary">#006837</color> <color name="colorPrimaryDark">#004012</color> <color
name="colorSurface">#FFFFFF</color> <color name="colorOnSurface">#0B0A0A</color> values/colors.xml -
Color Theming - Dark Mode? <color name="colorPrimary">#BA86FC</color> <color name="colorPrimaryDark">#000000</color> <color
name="colorSurface">#000000</color> <color name="colorOnSurface">#EAE4E4</color> values-night/colors.xml -
Color Theming - Dark Mode? <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorSurface">@color/colorSurface</item> <item name="colorOnSurface">@color/colorOnSurface</item> </style> -
Shape Theming <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#00ffffff"
/> <padding android:left="6dp" android:top="6dp" android:right="6dp" android:bottom="6dp" /> <corners android:radius="12dp" /> <stroke android:width="6dp" android:color="#ffffffff" /> </shape> -
Shape Theming <style name="ShapeAppearanceOverlay.RoundedCorner"> <item name="cornerSize">16dp</item> <item name="cornerFamily">rounded</item> </style> <com.google.android.material.imageview.ShapeableImageView
app:srcCompat="@drawable/cute_doggo" app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.RoundedCorner"/> -
Shape Theming <style name="ShapeAppearanceOverlay.RoundedCorner"> <item name="cornerSize">16dp</item> <item name="cornerFamilyTopLeft">cut</item> <item name="cornerFamilyBottomRight">cut</item>
<item name="cornerFamily">rounded</item> </style>