I've read from another post that it's possible to set attributes like color to every TextView in an application: Setting global styles for Views in Android. However, I can't set layout_margin nor layout_height and layout_width attribute using that method to any textView, using "android:textviewStyle". On the other hand, if I use the style attribute and reference it to a style with all the attributes above, it works. Is there a way that you can use global styles and still set margin?
Thank you in advance
You can set padding instead of margin and you will have the same result.
Related
As my title, when I'm using a theme, style or text appearance, which one takes precedent?
Is there any way I can use all three of them? Thanks!
According to the docs, the priorities are as follows:
Applying character- or paragraph-level styling via text spans to
TextView-derived classes
Applying attributes programmatically
Applying individual attributes directly to a View
Applying a style to a View
Default styling
Applying a theme to a collection of Views, an activity, or your
entire app
Applying certain View-specific styling, such as setting a
TextAppearance on a TextView
Does a TextView have some padding set by default? I'm trying to create two TextViews and I noticed that there's some padding in the TextViews without me explicitly setting it. If yes, then what's the value of it? Or where can I find more information on this?
Yes there exists font padding in android.
you could aswell disable it by
mTextView.setIncludeFontPadding(false);
or xml attribute
android:includeFontPadding="false"
I want a specific TextView to have the same font size as a Button, but they appear to be different. If my Button is not setting a custom textSize, how can I grab this value from the current theme and set it to the textSize of my TextView?
It should be fairly simple with styles. Buttons parent is android.widget.TextView so you could make a style that uses this as parent and overwrite the default textSize. Then let both use this style.
Through layout.xml it is working.
<RatingBar
android:id="#+id/hotel_rating_bar"
style="#style/custom_ratingbar" />
But i want to set the style Dynamically.
Any Answer will be highly appreciated...
Dynamically changing the style of views at runtime is not yet supported in Android, except for TextViews via setTextAppearance.
You have to set the style before the view gets drawn,
either via XML or via Java in the constructor.
RatingBar ratingBar = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);
There are always a few attribute values that Android doesn't explicitly define how to change and set dynamically for views. In my case, I'm trying to set the ListView's vertical scroll bar drawable. There's no method in the ListView class that lets you set this. I can only define this in the XML using android:scrollbarThumbVertical="#drawable/new_scroll_bar". Is there ANY workaround that would let me change attributes not otherwise defined dynamically?
It seems impossible, since the document doesn't refer to a corresponding method to set that XML attribute.
In the docs it says it corresponds to the global resource attribute:
android.R.attr.scrollbarThumbHorizontal
You can set this equal to a drawable programatically.
Ref: http://developer.android.com/reference/android/view/View.html#attr_android:scrollbarThumbVertical
Let me know if that is what you were trying to get to.