What is style

Android style is a just like css in html that is used to decorate the tag./p>

In my program i am going to create a simple style that change the color appearance and layout_height and layout_width of textview and button.


Style:.

In this section i am going to show the style with practical example.

First open the android studio and create a project and give the name of your project like StyleDemo.

The screenshots of the program is as follows:

Smiley face Smiley face

Drag and drop two textview and one button from pallet on to the MainActvity.

Explore the folder app->res->values->style.With in style the code is look like this.

<resources>

    
  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    
    @color/colorPrimary
    @color/colorPrimaryDark
    <item name="colorAccent">@color/colorAccent
    </style>
  
   
  <style name="textviewstyle">
    <item name="android:textColor">#FF0000</item>
    <item name="android:textStyle">bold</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Large</item>

    </style>
  <style name="buttonstyle">
    <item name="android:textColor">#0000FF</item>
    <item name="android:textStyle">italic</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Large</item>

</style>

</resources>


       

Explanation:

<style name="textviewstyle">:The style tag is used to define the style in android and its name is textviewstyle it is userdefined name user can give this name according to their facility.In my case i am going to apply on textview so i am giving the name as textviewstyle.

<item name="android:textColor">#FF0000</item>:The item tag is used to define the property.Here the android:textcolor property given the text color as red the color code is #FF0000 .

<item name="android:textStyle">bold</item>:This statement set the property textStyle as bold.

<item name="android:layout_height">wrap_content</item>:This statement set the layout height.

<item name="android:layout_width">match_parent</item>:This statement set the layout width.

<item name="android:textAppearance">@style/TextAppearance.AppCompat.Large</item>.This statement set the text appearnace as large.

<style name="buttonstyle">:The style tag is used to define the style in android and its name is buttonstyle it is apply on button in my case.

<item name="android:textColor">#FF0000</item>:The item tag is used to define the property.Here the android:textcolor property given the text color as blue. The color code is #0000FF .

<item name="android:textStyle">bold</item>:This statement set the property textStyle as bold.

<item name="android:layout_height">wrap_content</item>:This statement set the layout height.

<item name="android:layout_width">match_parent</item>:This statement set the layout width.

<item name="android:textAppearance">@style/TextAppearance.AppCompat.Large</item>.This statement set the text appearnace as large.



Style

What is style for video Click here

Smiley face                     Smiley face