How to specify the progressBarStyleHorizontal attribute in a style sheet - android

I want put the progressBarStyleHorizontal attribute in a style sheet.
I have tried something this, but it didn't work.
<style name="BarraProgreso">
<item name="android:progressDrawable">#android:style/Widget.ProgressBar.Horizontal</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">7dp</item>
<item name="android:indeterminate">true</item>
</style>
Do you know how could use this attribute within a style sheet?
Thanks in advance.

Well, nitzanj was right the problem is the style. Maybe this is what you want:
<style name="BarraProgreso" parent="#android:style/Widget.Holo.Light.ProgressBar.Horizontal">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">7dp</item>
<item name="android:indeterminate">true</item>
</style>
Where using the Holo.Light theme gives the following result:
And this is how you can use your new created style :
<ProgressBar
android:id="#+id/yourIDProgressBar"
style="#style/BarraProgreso" />
Hope this helps :)

The easiest solution would be to make your custom progress bar style extend the required style like so:
<style name="BarraProgreso" parent="#android:style/Widget.ProgressBar.Horizontal">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">7dp</item>
<item name="android:indeterminate">true</item>
</style>
Note that reason what you tried doesn't work is because you're trying to assign a style value into a drawable, which is impossible. By extending the original style you get all it's attributes while still being able to override any attribute, in case the parent style isn't 100% what you need.

Related

Avoid using an item in style

I have a style for a button bar. some thing like this:
<style name="Register.LayoutButtons">
<item name="android:orientation">horizontal</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1.0</item>
<item name="android:layout_marginTop">16dp</item>
<item name="android:background">#color/white</item>
</style>
Its OK for most of usage but in 1 place i don't need the layout_marginTop.
How can i cancel its effect without using a new style?
In the resource where you set the style of an item, you can also set layout_marginTop="0dp". Or if you do it dynamically there should be a setter - for example setMargins(left, top, right, bottom).

Overwrite only changed style properties for Android fragmentation

I define the followiung style in values/styles.xml of my application:
<style name="light_textview_style">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">#dimen/_1_BU</item>
<item name="android:textColor">#color/login_text</item>
<item name="android:textSize">#dimen/text_1_and_quarter_BU</item>
</style>
And in my values-xlarge/styles.xml I modify it the following way:
<style name="light_textview_style">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">#dimen/_1_BU</item>
<item name="android:textColor">#color/login_text</item>
<item name="android:textSize">#dimen/text_1_and_quarter_BU</item>
</style>
Basically changing only one property - layout_width becomes wrap content for large displays.
I have many such cases of styles. This means that I duplicate a huge number of properties between styles because of fragmenting just few properties.
Is there any cleverer way to reuse the declaration from values/styles.xml and specify explicitly only the changed properties?
You can have the parent style and derive two different styles from it.
Look at this link about: themes

ActionBarSherlock: changing homeAsUpIndicator doesn't work

I'm want to change the up icon with applying the following style to my activity, but it doesn't work and but I still get the default black '<' icon.
Can anyone find out what is missing here?
<style name="AppTheme.ActionBar" parent="#style/Theme.Sherlock.Light">
<item name="actionBarStyle">#style/actionBarStyle</item>
<item name="android:actionBarStyle">#style/actionBarStyle</item>
</style>
<style name="actionBarStyle" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="android:background">#drawable/header_bar</item>
<item name="background">#drawable/header_bar</item>
<item name="android:homeAsUpIndicator">#drawable/up_indicator</item>
<item name="homeAsUpIndicator">#drawable/up_indicator</item>
<item name="android:displayOptions">homeAsUp|showHome</item>
<item name="displayOptions">homeAsUp|showHome</item>
</style>
If I remember correctly, I worked around this issue by moving you should move the android:homeAsUpIndicator and homeAsUpIndicator elements into the main theme declaration. In other words, try:
<style name="AppTheme.ActionBar" parent="#style/Theme.Sherlock.Light">
<item name="actionBarStyle">#style/actionBarStyle</item>
<item name="android:actionBarStyle">#style/actionBarStyle</item>
<item name="android:homeAsUpIndicator">#drawable/up_indicator</item>
<item name="homeAsUpIndicator">#drawable/up_indicator</item>
</style>
<style name="actionBarStyle" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="android:background">#drawable/header_bar</item>
<item name="background">#drawable/header_bar</item>
<item name="android:displayOptions">homeAsUp|showHome</item>
<item name="displayOptions">homeAsUp|showHome</item>
</style>
Not sure whether I also had to move up the displayOptions, but you may want to give that a go too in case above doesn't work right away.
By the way, I find naming a style AppTheme.ActionBar and then inheriting from Theme.Sherlock.Light rather confusing. If it were an ActionBar specific style, I would've expected something like Widget.Holo.Light.ActionBar (or any of the other widget styles) as the parent. If it's your main theme, I'd name it accordingly. Up to you of course.
Edit: Updated answer after Jake's comment.

Set a consistent style to all EditText (for e.g.)

I'm trying to make all EditText's in my application have a consistent look. I'm aware that I can do something like this:
<style name="App_EditTextStyle">
<item name="android:background">#drawable/filled_roundededges_box_dark</item>
<item name="android:textColor">#808080</item>
<item name="android:layout_height">45dip</item>
</style>
Then I can make a particular EditText have this style by doing this:
<EditText ...
style="#style/App_EditTextStyle
...>
But this way I have to remember to set the style individually for each and every EditText in my application which is tedious, if not error prone.
Is there some way I could make this a part of a theme or something? This is so I don't have to associate this style to every EditText. Something like this fictitious code block:
<style name="App_Theme" parent="#android:style/Theme.Holo">
...
<item name="android:EditTextSyle">#style/App_EditTextStyle</item>
...
<style>
And then in my AndroidManifest.xml I have something like:
<application
....
android:theme="#style/App_Theme">
And Voila! all my EditText's have the consistent style without me having to specify the style for each instance.
Override the attribute pointing to the EditText style(named editTextStyle :) ) in your custom theme:
<style name="App_Theme" parent="#android:style/Theme.Holo">
<item name="android:editTextStyle">#style/App_EditTextStyle</item>
</style>
and make your custom style to extend Widget.EditText:
<style name="App_EditTextStyle" parent="#android:style/Widget.EditText">
<item name="android:background">#drawable/filled_roundededges_box_dark</item>
<item name="android:textColor">#808080</item>
<item name="android:layout_height">45dip</item>
</style>
Edit:
If you're using the much newer AppCompat related themes use the editTextStyle attribute without the android prefix:
<style name="App_Theme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="editTextStyle">#style/App_EditTextStyle</item>
</style>
#Luksprog answer is correct but not working for me. After some experimentation, I found out that removing the android namespace from editTextStyle made it work for me.
<style name="App_Theme" parent="#android:style/Theme.Holo">
<item name="editTextStyle">#style/App_EditTextStyle</item>
</style>
and make your custom style to extend Widget.EditText or if using the AppCompat theme Widget.AppCompat.EditText:
<style name="App_EditTextStyle" parent="#android:style/Widget.EditText">
<item name="android:background">#drawable/filled_roundededges_box_dark</item>
<item name="android:textColor">#808080</item>
<item name="android:layout_height">45dip</item>
</style>
First, define the style for your EditText. Make sure that the parent style is android:Widget.EditText
<style name="CustomEditTextStyle" parent="android:Widget.EditText">
<item name="android:textColor">#0F0F0F</item>
<!-- ... More items here if needed ... -->
</style>
After that, override the attribute android:editTextStyle in your custom theme. Be aware, if you are using the support library, you will also need to override the attribute editTextStyle (without the android namespace).
<style name="App_Theme" parent="...">
<item name="android:editTextStyle">#style/CustomEditTextStyle</item>
<item name="editTextStyle">#style/CustomEditTextStyle</item> <!-- For compatibility with the support library -->
</style>
If you just need to set a few simple parameters, like text color, the Android namespace has a few parameters that will do that without the need to declare a separate style for the edit text. Eg
<style name="MyStyle" parent="android:Theme.Material.NoActionBar">
<item name="colorPrimary">#color/black</item>
<item name="colorPrimaryDark">#color/white</item>
<item name="colorAccent">#color/white</item>
<item name="android:textColor">#color/black</item>
<item name="android:editTextColor">#color/black</item>
<item name="android:editTextBackground">#color/black</item>
....
</style>
<style name="App_Theme" parent="#android:style/Theme.Holo">
<item name="android:editTextBackground">#drawable/filled_roundededges_box_dark</item>
</style>

How to change the default divider color for all ListViews

I am trying to apply default styling for all the listViews from style.xml
Please note at some places I am using nested listViews.
In style.xml
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:windowContentOverlay">#null</item>
<item name="android:listViewStyle">#style/awesomeListViewStyle</item>
</style>
<style name="awesomeListViewStyle" parent="#android:style/Widget.ListView">
<item name="android:fadingEdge">none</item>
<item name="android:background">#color/orange</item>
<item name="android:divider">#EEEEEE</item>
</style>
This has no effect. In the Manifest Theme.MyTheme as my default theme.
Please advice :)
As mentioned in another answer as Bhavin and Mark pointed out, in your style you should also add
<item name="android:dividerHeight">1px</item>

Categories

Resources