Skip to content

How to use base styles

Klaus Schmidt edited this page Dec 4, 2019 · 5 revisions

The styles resource file (app/res/values/styles.xml) contains globally predefined styles for several layout elements (CardViews, Buttons, TextView). This should be used as a default style for each of the layout elements defined there. Using these default styles makes sure that the overall layout is consistent and can easily be modified if needed. And it is easier for you since you don't have to define each attribute for each layout element itself.

For each layout element multiple attributes are defined, for example margin, padding, background color, text appearance, height, width, ... .

How to use it:

  1. create a new layout element
  • Buttons: use Button with PalliCare.Button
  • CardView: use com.google.android.material.card.MaterialCardView with PalliCare.CardView
  • TextView: use TextView with PalliCare.TextView
  1. define unique id
  2. set the style attribute style="@style/PalliCare.xxx" (see example below)
  3. if any of the default attribute values which were predefined in the corresponding style doesn't fit you needs, you should use the default style anyway, but just overwrite these values (see example below)
  4. set additional layout attributes
<com.google.android.material.card.MaterialCardView
        android:id="@+id/your_cards_id"
        style="@style/PalliCare.CardView">

        <Button
            android:id="@+id/your_buttons_id"
            style="@style/PalliCare.Button"
            android:layout_marginBottom="0dp"/> <!--overwrited attribute-->

        <TextView
            android:id="@+id/your_textview_id"
            style="@style/PalliCare.TextView"/>

</com.google.android.material.card.MaterialCardView>

Feel free to add any style yourself. Have also a look at type.xml which can be used to define default TextAppearances or shape.xml for typical shapes (corners, radius, strokes, etc).

Clone this wiki locally