Avoid using an item in style - android

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).

Related

Which style item name refers to the marker for the items that are currently not selected in a ListPreference?

To rephrase my question: What should the XXXX be in the code for the style I use for the dialogs in my preferences?
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:fontFamily">#font/bkant</item>
<item name="textColorAlertDialogListItem">#color/colorAccent</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="XXXX">#color/colorAccent</item>
</style>
To clarify what I mean: I want to change the empty grey circles to the left of all items that are not "Five minutes" from grey to #color/colorAccent.
Okay, after trial and error with some of the options Android Studio suggested as autocompletion when I typed "color" where the XXXX was, I found that "colorControlNormal" did that trick:
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:fontFamily">#font/bkant</item>
<item name="textColorAlertDialogListItem">#color/colorAccent</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlNormal">#color/colorAccent</item>
</style>

add margin on popup menu items

I am using the default pop menu with custom font(by overriding the default font), but it seems like the items have a little margin from bottom:
I think this problem is because of my font, but I like this font and I don't want to change it.
Do you have any suggestions about how can I add some margin from top on menu items?
<style name="ucrop_popup_menu">
<item name="android:textColor">#color/black</item>
<item name="android:textSize">#dimen/_11sdp</item>
<item name="android:fontFamily">#font/graphit_regular</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:popupBackground">#drawable/match_radius</item>
<item name="android:dropDownHorizontalOffset">-16dp</item>
<item name="android:dropDownVerticalOffset">#dimen/_16sdp</item>
</style>

How to specify the progressBarStyleHorizontal attribute in a style sheet

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.

Android Spinner style top divider

I'm trying to change the style for the Spinner's top divider, but without success.
I can only get that to work:
http://s18.postimg.org/qbg7920mh/spinner.png
Is is possible? What item should I modify?
<style name="AppTheme" parent="AppBaseTheme">
<!--item name="android:spinnerItemStyle">#style/SpinnerItem</item-->
<!--item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItem</item-->
<!--item name="android:dropDownItemStyle">#style/TestSpinnerItemStyle</item-->
<item name="android:dropDownListViewStyle">#style/TestSpinnerStyle</item>
</style>
<style name="TestSpinnerItemStyle" parent="android:style/Widget.ListView.DropDown">
<item name="android:divider">#00b54a</item>
<item name="android:dividerHeight">5dp</item>
</style>
By looking at your code, there must be an obvious error!
Rename TestSpinnerItemStyle to TestSpinnerStyle in second part like:
<style name="TestSpinnerStyle" parent="android:style/Widget.ListView.DropDown">
...
</style>

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.

Categories

Resources