Course Content

Course Content

Description

Android Style and Theme Example

We have seen the concept of Style, how we can design a particular view into a specific style whether it's textView, editText, or button. And when we apply such Style to whole application it becomes a 'Theme'. Now we will see both of this Android Style and Themes Example concept practically.

First of all we will create a project named 'MyTheme'.

Firstly we will design its layout, for that we will open our 'activity_main.xml' file from 'layout' folder. In this we have used the default relative layout, and have take a textview with its ID set as 'textView2'.

After that we will provide text,

android:text=""Welcome To My Theme Demo!""

 

Now to design style we will go to 'values' folder, and than open 'colors.xml' file,

<color name=""colorPrimary"">#FF4081</color>

<color name=""colorPrimaryDark"">#303F9F</color>

We'll use this two colors to change in Statusbar and Titlebar.

After that we will open 'styles.xml' file, and then we will specify dress styles,

<style name=""AppTheme"" parent=""Theme.AppCompat.Light.DarkActionBar"">

<item name=""android:colorPrimary"">@color/colorPrimary</item>

<item name=""android: colorPrimaryDark"">@color/colorPrimaryDark</item>

</style>

 

Now we will design second style for textview,

<style name=""MyTextViewStyle"" parent=""@android:style/TextAppearance.Large"">

<item name=""android:layout_width"">fill_parent</item>

<item name=""android:layout_height"">wrap_content</item>

<item name=""android:textColor"">4006633</item>

<item name=""android:typeface"">monospace</item>

<item name=""android: background"">#f07977</item>

<item name=""android:textStyle"">bold</item>

</style>

 

Now to apply theme we will first go to our manifest file, now in that default code we will apply theme,

android:theme=""@android:AppTheme"">

 

Now we will apply at second style in this manifest file, for that we will open layout 'activity_main.xml' file, and add our style,

style=""@style/MyTextViewStyle""

 

So now in this particular program, we have not changed any default code of our 'MainActivity.java' file. We have just added our style and theme code in Manifest and Layout file.

After executing, this program runs successfully.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere