In Android, Styles and Themes are a powerful way to customize the look and feel of your application. They allow you to define the visual style of your app in a central place, making it easier to maintain and modify.
What are Styles?
A Style in Android is a collection of attributes that specify the appearance of a single View. A Style can specify attributes such as font color, font size, background color, and much more.
Here’s an example of how to define a style:
<style name="MyTextStyle">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#008577</item>
</style>
You can apply this style to a View like this:
<TextView
style="@style/MyTextStyle"
android:text="Hello, World!" />
What are Themes?
A Theme is a collection of styles that can be applied to an entire Activity or application, rather than an individual View. When you apply a theme, every View in the Activity or application will apply each style attribute that it supports.
Here’s an example of how to define a theme:
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#008577</item>
<item name="colorPrimaryDark">#00574B</item>
<item name="colorAccent">#D81B60</item>
</style>
You can apply this theme to an Activity in the AndroidManifest.xml file like this:
<activity android:name=".MainActivity"
android:theme="@style/MyTheme">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>