I created a few drawables to handle state colors, etc for list view items. These work when I set the android:listSelector property to them on the list definition in the layout. But, I'd like to apply them globally, so in my theme, I declared the style, like:
<style name="QFListView" parent="#android:style/Widget.ListView">
<item name="android:listSelector">#drawable/listview_selector</item>
</style>
Why doesn't this work, or, what should I be doing to get it to work?
Android first draws the ListView background as well as the dividers. Then, the system draws the list selector. Finally, ListView renders all itemviews on top of that. Thanks to this diagram, it is clear the list selector will never be visible with opaque background set to itemviews.
Read this : #Customizing itemviews background
http://cyrilmottier.com/2011/08/08/listview-tips-tricks-3-create-fancy-listviews/
Related
What are the key differences between android:theme and style attributes used for views like buttons and textviews in android layout xml files?
How to use them?
and When to use which?
There are two key differences:
First, attributes assigned to a view via style will apply only to that view, while attributes assigned to it via android:theme will apply to that view as well as all of its children. For example, consider this style resource:
<style name="my_background">
<item name="android:background">#drawable/gradient</item>
</style>
If we apply it to a LinearLayout with three child TextViews by using style="#style/my_background", then the linearlayout will draw with a gradient background, but the backgrounds of the textviews will be unchanged.
If instead we apply it to the LinearLayout using android:theme="#style/my_background" then the linearlayout and each of the three textviews will all use the gradient for their background.
The second key difference is that some attributes only affect views if they are defined in that view's theme. For example, consider this style resource:
<style name="checkboxes">
<item name="colorAccent">#caf</item>
<item name="colorControlNormal">#caf</item>
</style>
If I apply this to a CheckBox using style="#style/checkboxes", nothing will happen. If instead I apply it using android:theme="#style/checkboxes", the color of the checkbox will change.
Just like the first rule said, styles containing theme attributes will apply to all children of the view with the android:theme attribute. So I can change the color of all checkboxes in a linearlayout by applying android:theme="#style/checkboxes" to my linearlayout.
I have a custom theme created with this generator. It has a custom style for Spinners which I don't like. I want to change the background drawable but I can't seem to figure out which property controls this.
This is what the themed version looks like
And here is what it will look like when using the Holo.Light theme.
Notice the dark gray lines around the dropdown list in the first (themed) image. This is what I want to get rid of. What property controls this? I want them to match the default.
Also, what controls the vertical aligment of the dropdown list? As you can see, it is overlapping with the Spinner in the first image (the line under it isn't visible as it is in the second image).
The attribute you want is android:popupBackground on the Spinner element.
If you look closely, the holo popup also overlaps the spinner some, but there is a bunch of padding for the drop shadow, so it looks good.
However, you can use android:dropDownVerticalOffset on the Spinner element to adjust it.
We came across the same issue. It has to do with the Android Holo theme generator.
Here are the lines that you should remove from your Theme.xml file...
<item name="android:spinnerStyle">#style/SpinnerCustom</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemCustom</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Custom</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Custom</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Custom</item>
...by removing these, we now have the standard Holo.Light theme on the spinner dropdowns.
You need to change the parent of spinnertheme to android:Widget.Holo.Light.Spinner
<style name="SpinnerTHEME" parent="android:Widget.Holo.Light.Spinner">
<style name="spinner_style" parent="android:Widget.Holo.Light.Spinner">
<item name="android:paddingLeft">#dimen/ten_dp</item>
<item name="android:paddingRight">#dimen/ten_dp</item>
</style>
I've written a simple custom style in xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Light">
<item name="android:textColor">#color/text_light</item>
<item name="android:background">#color/background_light</item>
</style>
</resources>
However, when I apply it, the text color is correctly set for every element of the view, whereas the background color is not set for the whole screen, but only for the single views inside it (for example listviews, textviews, buttons).
This is the code I use to set the theme:
public void onCreate(Bundle icicle) {
this.setTheme(R.android.Light);
super.onCreate(icicle);
How can I change the background color for the whole layout?
<item name="android:windowBackground">#color/background_light</item>
<item name="android:colorBackground">#color/background_light</item>
Note that the color needs to supplied as a separate resource here because the android:windowBackground attribute only supports a reference to another resource; unlike android:colorBackground, it can not be given a color literal.
(quoted from http://developer.android.com/guide/topics/ui/themes.html)
You must apply a theme to an Activity or application to apply the background image across the whole application.
Here is a link check out this tutorial
I just tried the current Google sample for ExpandableListiew: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html
This sample seem very simple and easy to use.
But what I would like to do is to say that change back ground color for child element and group element.
it doesn't uses any child_row.xml , group_row.xml.
please tell me the right way to do.
Thank a lot for any information.
you can define new style for the expandable list view like below...
<style name="Widget.MyExpandable" parent="android:Widget.ExpandableListView">
<item name="android:listSelector">#drawable/list_selector_background</item>
<item name="android:divider">#color/ex_listview_stroke</item>
<item name="android:cacheColorHint">#color/color_foreground</item>
<item name="android:dividerHeight">0.5dp</item>
</style>
in hear list_selector_background is the drawable selector file in which you can define several states for the EXList view like stander and pressed etc...,
and to have different background for the child and parent you need to create separate... drawable background file for childview.xml and parentview.xml
In my current implementation, I have modified the whole style of my application...
I successfully modified the Spinner style, so I was able to change the RadioButton look and feel:
I am now working on the title, but seems really hard to style.
I would like to change, for instance the title text color (and optionally removing the triangle)
I know I could do that by extending Spinner or Dialog, but I have to do achieve that by playing with xml.
Here is my current code that succesfully modified other dialog properties:
<style name="Theme.HoloEverywhereDark.Sherlock" parent="Theme.Sherlock">
<item name="android:spinnerStyle">#style/SpinnerDark</item>
<item name="android:spinnerItemStyle">#style/SpinnerItemDark</item>
<item name="android:spinnerDropDownItemStyle">#style/DropDownItemDark</item>
</style>
To change the triangle, you could use the second answer here: How to create android spinner without down triangle on the right side of the widget
I haven't yet figured out how to style the main text, but you may just be able to apply normal text field formatting to it via the Spinner in xml (textColor, etc).