-
Notifications
You must be signed in to change notification settings - Fork 377
Migrating from AppCompat
ZieIony edited this page May 18, 2015
·
1 revision
You already have a (more or less complete) app based on the AppCompat library? Wonder how to convert it to Carbon and how much (or little) work that entails? Well, read on!
-
Replace layouts with their Carbon counterpart.
LinearLayout
becomescarbon.widget.LinearLayout
and so on. This enables shadows, elevation and clipping on contained views. -
Use Carbon views for shadows and/or ripples:
- Replace standard views with their Carbon counterparts.
- Let your custom views inherit from the Carbon counterparts instead of the standard views.
- Let your custom views implement the Carbon interfaces, if there is no Carbon view you can use directly. For more information read the Advanced Usage section.
- Inherit your base theme from Carbon instead of AppCompat. The themes
carbon_Theme.Light
andcarbon_Theme.Dark
themselves inherit the Appcompat theme. Make sure to replace your base theme for all API versions, not just the basic version!
- Views that draw a shadow must have a completely opaque background. Unset backgrounds (null), backgrounds set to the color transparent as well as semitransparent backgrounds will show the blackness of the shadow inside the view. On Lollipop devices this looks like a trapezoid shadow. On pre-Lollipop devices the whole view is greyish. To achieve seemingly transparent views use the color of whatever is behind the view, e.g.
?android:attr/windowBackground
- Views need space to have their shadow drawn. This can either be achieved by giving them a margin (but not a padding) or setting clipChildren of the surrounding ViewGroups/layouts to false. The margin required to display the shadow created by a view is equal to its Z-Value (elevation + translationZ).
Copyright 2015 Marcin Korniluk 'Zielony'