Project Url: airbnb/paris
Introduction: Define and apply styles to Android views programmatically
More: Author   ReportBugs   

Paris lets you define and apply styles programmatically to Android views, including custom attributes.

  • Apply styles programmatically at any time.
  • Combine multiple styles together.
  • Create styles programmatically (as opposed to using XML).
  • Use annotations to easily support custom attributes (inspired by Barber).
  • Declare explicitly supported styles for your custom views.
  • And much more...


In your project's build.gradle:

dependencies {
    implementation ''
    // If you are using Paris annotations
    implementation ''
    annotationProcessor ''

To use Paris in a library module see Library Modules.

Quick Start

Applying an XML-Defined Style;

Where myView is an arbitrary view instance and MyStyle an XML-defined style. Many but not all attributes are supported, for more see Supported View Types and Attributes.

Combining 2 or More Styles


In cases where there's some overlap the attribute value from the last style added prevails. For more see Combining Styles.

Defining Styles Programmatically

        .textColor(Color.GREEN) // Using an actual value
        .textSizeRes(R.dimen.my_text_size_small) // Or a resource

Can be combined with style resources as well:


For more see Defining Styles Programmatically.

Custom View Attributes

Attributes are declared as followed:

<declare-styleable name="MyView">
    <attr name="title" format="string" />
    <attr name="image" format="reference" />
    <attr name="imageSize" format="dimension" />

The custom view is annotated with @Styleable and @Attr:

// The value here corresponds to the name chosen in declare-styleable
public class MyView extends ViewGroup {

    public MyView(Context context) {

    public MyView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);

    public MyView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // Enables the custom attributes when used in XML layouts;

    public void setTitle(String title) {

    public void setImage(Drawable image) {

    public void setImageSize(@Px int imageSize) {

The @Attr-annotated methods will be called by Paris when the view is inflated with an AttributeSet or when a style is applied.

For more see Custom View Attributes.

Styling Subviews

Attributes are declared as followed for the 2 subviews we'd like to be able to style:

<declare-styleable name="MyHeader">
    <attr name="titleStyle" format="reference" />
    <attr name="subtitleStyle" format="reference" />

The subview fields are annotated with @StyleableChild:

public class MyHeader extends ViewGroup {

    TextView title;

    TextView subtitle;

    // Make sure to call during initialization

The title and subtitle styles can now be part of MyHeader styles:

    app:subtitleStyle="@style/Regular" />
        .titleStyle( // Defined in XML
        .subtitleStyle((builder) -> builder // Defined programmatically

For more see Styling Subviews.

Linking Styles to Views

public class MyView extends View {

    // For styles defined in XML
    static final int RED_STYLE =;

    // For styles defined programmatically
    static void greenStyle(MyViewStyleApplier.StyleBuilder builder) {


Helper methods are generated for each linked style:; // Equivalent to .apply(; // No equivalent

        .addRed() // Equivalent to .add(
        .addGreen() // No equivalent

For more see Linking Styles to Custom Views.


See examples and browse complete documentation at the Paris Wiki.

If you still have questions, feel free to create a new issue.


We love contributions! Check out our contributing guidelines and be sure to follow our code of conduct.


Copyright 2018 Airbnb, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
Support Me
About Me
Google+: Trinea trinea
GitHub: Trinea