Where is #style/MyActionBarTitleText - android

I’m new to android and are looking at tutorials to learn android development. I'm trying to figure out how all the xml files and tags are fit together.
In a google tutorial for actionbars one custom style, in themes.xml, look like this:
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
I don't find or understand where "#style/MyActionBarTitleText" is defined and i don't get any compiling error in Eclipse. When a tag is referenced like this i thought it has to be defined in a xml file under my project somewhere but i cant find it?

Style XMLs are defined in res/drawable[-mdpi/ldpi/xhdpi]
Style defines look of your Activity. You can define color, themes, shapes in Styles. Read more about styles and other resources here
http://developer.android.com/guide/topics/resources/style-resource.html
http://developer.android.com/guide/topics/resources/available-resources.html

Yes you can find it in: res->values->styles.xml
and also you can change your application theme/style in styles.xml file

Related

Android built-in styles

I'm a learner of Android programming and I'm currently reading this book, well it's the first, HeadFirst Android Development.
In chapter 14 Navigation Drawers, there was this attribute of TextView textAppearance that was given a value of #style/textAppearance.AppCompat.Body1.
The book said it was a built-in styles that makes text look slightly bolder.
My question is, how many built-in styles does Android has?
I want to know all of them.
If you go through the following link you will get all the styling options for TextView.
https://developer.android.com/reference/android/widget/TextView
you can check the styling options for other views from the left panel of the same link by clicking on other classes.
A style is defined in an XML resource that is separate from the XML that specifies the layout. This XML file resides under res/values/ directory of your project and will have as the root node which is mandatory for the style file.
You can define multiple styles per file using tag but each style will have its name that uniquely identifies the style. Android style attributes are set using tag as:
<?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 defined, you can use it in your XML Layout file using style attribute as follows
<TextView
android:id="#+id/text_id"
style="#style/CustomFontStyle"
android:text="#string/hello_world" />
Always, when you are writing in XML to find the built-in attribute use:
attribute_name="#android:attribute_value
The #android: will list all the built-in the attribute for a given attribute you want, for Example:
style="#android:style/TextAppearance.AppCompat.Medium"
Default Styles & Themes
Android provides a large collection of styles and themes that you can use in your applications. You can find a reference of all available styles in the R.style class. To use the styles listed here, replace all underscores in the style name with a period. For example, you can apply the Theme_NoTitleBar theme with "#android:style/Theme.NoTitleBar".
You can see the following source code for Android styles and themes- here and here

Prefix in android style files item names

I am new to android and have a question about the styles.xml file.
Each item for example this
<item name="android:background">#color/black</item>
works both with "android:background" and with just "background".
What is the android: prefix there for?
When creating your own styles, you should always extend an existing style from the framework or support library so that you maintain compatibility with platform UI styles. To extend a style, specify the style you want to extend with the parent attribute. You can then override the inherited style attributes and add new ones.
For example, you can inherit the Android platform's default text appearance and modify it as follows:
<style name="GreenText" parent="#android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
However, you should always inherit your core app styles from the Android Support Library.
But if you don't inherit them from the android support library then too things will work the same!
Source: Explanation text and code taken from: https://developer.android.com/guide/topics/ui/look-and-feel/themes
You can read more about Styles and Themes from the above doc, from where I took the example to explain you!

How can I call the style of a new Library as parent in style.xml?

I am building a new library for Android and a demo project that I am using to test the library.
The library that I made has a style called Light and in the demo I am applying this style in Java using setTheme(R.style.Light) but I would like to replace it calling the theme directly in style.xml. What I have right now in the demo/res/values/style.xml is
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
and I would like to replace it with something similar to:
<style name="AppTheme" parent="myLibrary.Light">
I have tried with parent="#style/Light" but it's not working.
Does anyone know how I can do it?
To inherit styles from a library or your own project, declare the parent style name without the #android:style/ part. For example, the following example inherits text appearance styles from the support library:
<style name="GreenText" parent="TextAppearance.AppCompat">
<item name="android:textColor">#00FF00</item>
</style>
For more details
I found the solution,
My problem was that in my library I had different styles depending on the version of Android. For each version of Android my main theme was referred to different parents by mistake. I just changed the parents in my library making sure that they are referring to the same one and it fixed my problem. Now in my app I can refer to the theme created in my library without crashing the application.

ActionBarSherlock with Action Bar Style Generator

for the last few days I'm trying to implement custom theme, which is created by Action Bar Style Generator to my application. I'm able to use theme with some generic samples from SDK, but I'm not able to use it with my application which uses ActionBarSherlock.
My application with ActionBarSherlock is a modified sample of Tabs and Pager.
Steps which I do:
Create theme with Android Action Bar Style Generator.
Copy theme to res folder inside my application.
Change theme in Manifest file.
After those steps only 'Action bar color' changes to correct one. All other styles are not used in application. I have tried many different approaches which I found online, but without success.
Thank you very much for your help.
Did you add the proper items to your App's theme in styles.xml? You need to use attributes that are NOT prefixed with android:, for example:
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="background">#drawable/bg_striped</item>
<item name="backgroundSplit">#drawable/bg_striped_split</item>
You would also keep the properly prefixed ones for Android versions that have native actionbar.
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:background">#drawable/bg_striped</item>
<item name="android:backgroundSplit">#drawable/bg_striped_split</item>
The best place to understand this is to look at the demo provided with the ActionBarSherlock library project.
I managed to fix the problem.
I missed android:background attribute in TabWidget. This partially
solves the problem.
I had to set setLeftStripDrawable and setRightStripDrawable programatically.

Android: HowTo make device theme

perhaps I don't know how to search for that - everything I found only is about changing the app theme.
I want to know how I can develop a whole theme for the android device itself?
On the market you'll find many themes out there - how can I build one, too?
I don't want to use 3rd party licences (ThemeMaker etc)...anyone who has a tutorial for me?
Thanks for your help!
You should read up on the Android Developer site - Styles and Themes http://developer.android.com/guide/topics/ui/themes.html
A style is a collection of properties that specify the look and format for a View or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.
Styles in Android share a similar philosophy to cascading stylesheets in web design—they allow you to separate the design from the content.
Apply a theme to an Activity or application
To set a theme for all the activities of your application, open the AndroidManifest.xml file and edit the <application> tag to include the android:theme attribute with the style name. For example:
<application android:theme="#style/CustomTheme">
If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional light theme to use your own color like this:
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>

Categories

Resources