Often i like default android style defined for some widget.
Often i like to just slightly modify this default style, not create my own style from a scratch.
Now, i use android.R.layout.simple_spinner_dropdown_item as dropDownViewResource on my spinner adapter - like this:
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
I can open this layout xml file and copy its content to modify it. But the most important part of that xml file is attribute style, it looks like this: style="?android:attr/spinnerDropDownItemStyle"
Now, my question is: how do i find/view/copy this style spinnerDropDownItemStyle, so i can for example just change background color.
Thanx for your help
here you can find style spinnerDropDownItemStyle:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml
But, if you looking for change background of Spinner, you'll need to search for 9 patch images:
https://developer.android.com/studio/write/draw9patch.html
And here a good example:
http://www.gersic.com/blog.php?id=57
Ty
My suggestion to you is . you can make a seprate custom layout and put it on your spinner setDropDownResource()
adapter.setDropDownViewResource(android.R.layout.CUSTOM_LAYOUT);
Now you can easily make a style for your layout
Related
I am having a problem, i know how to set colors programmatically using the following method
For Example:
imageButton.setColorFilter(ContextCompat.getColor(this,R.color.colorAccent));
This works just fine what about if i don't want to set the colors from colors.xml for example
the following colors in XML
android:background="#android:color/holo_orange_dark"
I want to set the colors above programmatically i don't want to use the colors in colors.xml
Use this
getResources().getColor(android.R.color.holo_orange_dark)
Here's the full code:
imageButton.setColorFilter(getResources().getColor(android.R.color.holo_orange_dark));
Hope this helps. Feel free to ask for clarifications...
I read about Android styles and themes today and tried to apply it to a list in my app as a test. The app has a list element which have TextViews added to it programmatically.
According to the docs applying a style as a theme affects child views too.
So I tried this:
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextAppearance.AppCompat.Small"/>
I expected that the TextView texts in the list became small, but nothing happened.
I also tried #style/TextAppearance.MaterialComponents.Headline1, but it had no effect either.
Why is that?
I didn't change any of the style or theme settings myself. I use the default settings which Android Studio generated for the project.
Shouldn't applying a style as a theme to a view like above change something?
You are using the style "TextAppearance.AppCompat.Small" which is applicable to a TextView and not a generic one like ListView.
You need to apply the style to the list item which is the TextView. You can create a custom style for text appearance, font, sizing, etc and reuse it in your entire app.
If you are creating your views programmatically, you can use a custom adapter (which extends your default adapter), override getView method to apply your style. Refer this
Refer to this awesome article by #Nick Butcher
I'm stuck with a very strange issue.
I can't change the TextColor of some TextViews around the app, neither with the android:textColor="" nor by setting a style. It only works if I change it at runtime. This problem appeared without any change related to the activity in question. The most strange thing is that in the Preview the colors are fine, but when I run it, the colors are always the same.
What might be overriding the textColor value set in the XML ?
Thx Anticipately
P.S:
Along all the App I can only change the color of the textHint
I had to remove all the N preview stuff from my sdk to make things normal again. Don't forget the cache too.
sdk/extras/android/m2repository/com/android/support/design|support-v-13|ect./24~
The syntax of xml line you wrote is wrong
instead of
android:setTextColor=""
use
android:textColor=""
You can change the Text Color in layout XML by using android:textColor
example:
android:textColor="#0E0E9A"
it overrides the style.xml
the only way to override your layout.xml is by code
example:
mEditText.setTextColor(Color.DKGRAY);
Currently, am setting the background of a TextView using code like this:
textView.setBackgroundResource(R.drawable.rect_with_border_grey);
I then came to know about dimens.xml usage and how you can set through that file. Is it possible to set the background through ? i.e. I want to do the above code line through XML. Any help please?
I wouldn't do this using layout xml file as #Opiatefuchs pointed out (in the comment below). B'cos, this textview's background will change depending on the user setting in the App dynamically.
Make a style like
<style name="MyTextStyle">
Do everything you want to do with your TextView here.
</style>
and then assign that style to your textview in xml like this
style="#style/MyTextStyle"
It will work.
dimen.xml is only use for giving dimension only. for setting background you need to do it with either layout xml file or from java.
Its up-to the requirement of setting background.
I finally found that you cannot set the background of a TextView via element (i.e. XML) in Android. You need to use layout XML. But, in my case, I cannot use layout since the background will change dynamically based on user choice in the App.
create dimens.xml file like this:
<resources>
<dimen name="paddingTop">10dp</dimen>
<dimen name="paddingRight">20dp</dimen>
...
</resources>
then use it in your layout xml files like this:
android:layout_marginTop="#dimen/paddingTop"
android:layout_marginTop="#dimen/paddingRight"
I need to use perticular image as the theme for my most of the activities in my application...
please help me how to do this..
Basic idea is to define and apply the custom style of your Activities in Res files. Tutorial here.
if your using XML display there is a field background
#drawable/custom_dialog_background
or
android:background in the XML anchors
setBackgroundResource(int) in your code
http://developer.android.com/reference/android/view/View.html#attr_android:background