Creating Styles in android
Styles and themes on Android make it possible for you to separate the details of our app design from the UI structure and behavior, identical to stylesheets in web design. We will use this in our project to maintain a consistent style, so that we won't have to hardcode it to each element. A style is a set of attributes that determine the appearance of a single View. A style can define features like font color, font size, background color, and a lot more.
To make a style you want to navigate to res/values/styles.xml in this file you can make styles. Fot this example we will make a buttonstyle that we can implement across multiple buttons. To make a style you need to add this code to your style.xml file
| <resources>
<style name="ButtonStyle">
</style>
</resources>
|
After that, you may add your styling items in the code.
| <style name="ButtonStyle">
<item name="android:textSize">24sp</item>
<item name="android:textColor">#000000</item>
<item name="android:background">#F0F0F0</item>
<item name= "android:textStyle">bold</item>
<item name="android:padding">16dp</item>
<item name="android:layout_margin">8dp</item>
</style>
|
If you have done this, return to your activity.xml file and add the style element to your object. You will need to connect your style to the element.
| <Button
android:id="@+id/homeButton"
style="@style/ButtonStyle"/>
|
You can now add this to multiple buttons to keep the same style and avoid copying and pasting the same feature