In several android styling tutorials parent style elements are used that i can not find in the android.R.style.* styles (http://developer.android.com/reference/android/R.style.html).
A few examples are from the http://android-developers.blogspot.com/2011/04/customizing-action-bar.html action bar article. Nick uses parent styles like:
<style name="MyDropDownNav" parent="android:style/Widget.Holo.Light.Spinner.DropDown.ActionBar">
...
</style>
or
<style name="MyActionBarTabStyle" parent="android:style/Widget.Holo.Light.ActionBarV开发者_开发百科iew_TabView">
...
</style>
Where do these parent styles come from? Is it possible to list all available parent styles?
Thanks.
As stated in the "Applying Styles and Themes" article:
The Android platform 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"
.The R.style reference, however, is not well documented and does not thoroughly describe the styles, so viewing the actual source code for these styles and themes will give you a better understanding of what style properties each one provides. For a better reference to the Android styles and themes, see the following source code:
- Android Styles (styles.xml)
- Android Themes (themes.xml)
These files will help you learn through example. For instance, in the Android themes source code, you'll find a declaration for
<style name="Theme.Dialog">
. In this definition, you'll see all of the properties that are used to style dialogs that are used by the Android framework.
For "android:style/Widget.Holo.Light.ActionBarView_TabView" see: http://developer.android.com/reference/android/R.style.html#Widget_Holo_Light_ActionBar_TabView ...and note the API level it was introduced at!
For "android:style/Widget.Holo.Light.Spinner.DropDown.ActionBar" try: http://developer.android.com/reference/android/R.style.html#Widget_Holo_Light_DropDownItem_Spinner
The latter is just my best guess - I can't get the list to actually drop down.
Parent
attribute is a optional one while creating your own themes
or styles
.
Basically parent
attributes are used for inheriting the styles which are already defined in the platform itself.
If we wish to inherit a theme
or style
and overwriting some features, we can use parent
attribute.
Here's a link for the all available platform defined styles
.
And one more tip :
If you want to inherit your own style
that you created by yourself means follow this example to inherit.
<style name="MyDropDownNav.Red">
<item name="android:textColor">#FF0000</item>
</style>
Here is Official Google's Documentation
for Default List
of Themes
and Styles
Google Android Documentation
You can Find here in this documentation
- Android Styles (styles.xml)
- Android Themes (themes.xml)
I know the answer to above question finishes over here still giving way of implementation, as it will be helpful for novices..
How to Implement them
This is what i got from the themes.xml
<style name="Theme.NoTitleBar">
<item name="android:windowNoTitle">true</item>
</style>
Now to implement
it in my project
I have to add the following line in my Styles.xml
file
<style name="AppTheme" parent="android:Theme.NoTitleBar" />
In this I am creating my own theme
named "AppTheme
" which will inherit
its properties from already defined them by google
. so I am mentioning it in parent
By looking into themes.xml
and styles.xml
will not only help to get the list of the already defined
themes and styles but also help novices to have an idea how to create
the themes.
As the theme I am mentioning here in parent
is already defined by android so we will use it by prefixing the android:
to theme name ..
If You want to inherit your created theme
then
<style name="Theme2" parent="AppTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
then just provide the style name to the parent
, here i am using Apptheme
as parent theme for theme2
精彩评论