A style is characterized in a XML asset that is separate from the XML that determines the design. This XML document lives under res/values/registry of your task and will have as the root hub which is obligatory for the style record. The name of the XML record is self-assertive, yet it must utilize the .xml expansion.
You can characterize numerous styles per record utilizing tag however every style will have its name that interestingly recognizes the style. Android style properties are set utilizing tag as appeared beneath.
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="CustomFontStyle"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:capitalize">characters</item> <item name="android:typeface">monospace</item> <item name="android:textSize">12pt</item> <item name="android:textColor">#00FF00</item>/> </style> </resources>
Using Styles
Once your style is characterized, you can utilize it in your XML Layout document utilizing style trait as takes after −
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/text_id" style="@style/CustomFontStyle" android:text="@string/hello_world" /> </LinearLayout>
Applying Colors to Theme Attributes
<resources> ... <style name="MyCustomTheme" ...> <item name="android:windowBackground">@color/my_custom_color</item> <item name="android:colorBackgroundCacheHint">@color/my_custom_color</item> </style> ... </resources>
Styles & Themes
The Android stage gives a substantial accumulation of styles and topics that you can use in your applications. You can discover a reference of every single accessible style in the R.style class. To utilize the styles recorded here, supplant all underscores in the style name with a period. For instance, you can apply the Theme_NoTitleBar subject with “@android:style/Theme.NoTitleBar”. You can see the accompanying source code for Android styles and topics −
Android Books To Learn Mobile Apps Programming
- Android Programming: The Big Nerd Ranch Guide
- Android Design Patterns: Interaction Design Solutions for Developers
- Android Application Development Cookbook – Second Edition
- Android User Interface Design: Turning Ideas and Sketches into Beautifully Designed Apps (Usability)
- Android Recipes: A Problem-Solution Approach for Android 5.0
- Hello, Android: Introducing Google’s Mobile Development Platform (Pragmatic Programmers)
- Beginning Android Games
Leave a Reply