Change icon of expandable list view - android

I would like to change the expanded and default icon of my Expandable List View.
I did some research how to do this and found this question.
I think I did it just as it is described there.
I have 2 icons, the first is called defaulticon.png and the second one expandedicon.png. Bother are located in the drawable folder (not in drawable-hdpi).
My list view declaration looks like this:
<ExpandableListView
android:id="#+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:groupIndicator="#drawable/groupindicator">
</ExpandableListView>
The groupindicator is an xml file also located in the drawable folder and looks like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/defaulticon" android:state_empty="true"/>
<item android:drawable="#drawable/expandedicon" android:state_expanded="true"/>
</selector>
However the icons do not change. The default icon from the list view disappears and instead there is no icon.
Are there any restrictions with the resources (how big the resources can me (both are 160x160), where they have to be located,...).
I am testing the app on my S3 running Android 4.1.2.
Cheers

Change your icon size to 32 X 32, put your icon in drawable-mdpi and then try this code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/expandedicon" android:state_expanded="true"/>
<item android:drawable="#drawable/defaulticon"/>
</selector>

First of all, resize your image to 24*24 and then copy it to the drawable-mdpi folder in Android. After that, copy and paste this code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/abc"android:state_empty="true"></item>
<item android:drawable="#drawable/downarrow" ></item>
</selector>

Related

Make a API-dependent reference to a theme-style

API 21+:
android:background="?android:attr/selectableItemBackgroundBorderless"
API <21:
android:background="?android:attr/selectableItemBackground"
How is it possible?
I know the solution that uses "?attr/API_dependent_theme_reference" like this. This doesn't work for App Widget layout, unfortunately.
Also, I know the solution uses style="..." for the view and multiple style definitions in values and values-v21 folders. But looking for a way to directly assign the background property (especially as Android, unfortunately, don't support assigning multiple styles like CSS: class="style1 style2 etc"!).
You can have two custom drawables
drawable/backround_name.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="?android:attr/selectableItemBackground"
</layer-list>
and
drawable-v21/backround_name.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="?android:attr/selectableItemBackgroundBorderless"
</layer-list>

rollover android

I want to make a rollover with android.
I saw that it is necesarry to write a XML like :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/verde" />
<item android:drawable="#drawable/rojo" />
</selector>
I saved it with the name button.xml.
I don't know in which folder save it.
Then I tried to used the reference in my layout.xml
I change the background attribute for my button in my layout.xml from
android:background="#drawable/red"
and use the
android:background="#drawable/button"
Save button.xml in the folder res/drawable if it's applicable for all screen sizes/devices, otherwise put it in the folder with the appropriate qualifier suffix (e.g. drawable-hdpi, drawable-ldpi etc).
See here (http://developer.android.com) for a full example, and explanation of other states you could include.

Change checkMark or size of CheckedTextView

I'm working on an application where I'm using a checkedTextView, it all works great. But I really don't like that layout of the "checkbox" within the checkedTextView, it's simply to big. Is there any way to resize it or change the layout to something custom made?
I've tried the android:checkMark attribute, but that resulted in it being marked all the time, and thus showing all the time.
Instead of using a single drawable you should write a selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/drawable_checked"
android:state_checked="true" />
<item
android:drawable="#drawable/drawable_unchecked"
android:state_checked="false" />
</selector>
And then set it to the android:checkMark attribute.

How to show custom thumb when using fastScrollEnabled

I have a listview of countries in non-alphabetic order and started using fastscroll. I would like to display the country-flag when scrolling with fastscroll but it seems like the APIs has the FastScroll class as private so I cannot override it.
Have anyone else implemented a custom fastscroll view?
References:
http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:fastScrollEnabled
In your ListView XML definition, add
android:fastScrollEnabled="true"
or in code
listView.setFastScrollEnabled(true);
Create file fastscroll_thumb.xml in the res/drawable folder as follows:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/fastscroll_pressed" />
<item android:drawable="#drawable/fastscroll" />
</selector>
In AndroidManifest.xml, set a custom theme for your application:
<application
android:theme="#style/ApplicationTheme"
...>
Create a values folder in the res folder. Create themes.xml files in res/values as follows:
<resources>
<style name="ApplicationTheme">
<item name="android:fastScrollThumbDrawable">#drawable/fastscroll_thumb</item>
</style>
</resources>
Lastly make sure that fastscroll.png and fastscroll_pressed.png exist in your drawable folder
(optional)
You can also set fast scroll always visible while you are debugging if you like
listView.setFastScrollAlwaysVisible(true);
or in XML
android:fastScrollAlwaysVisible="true"

Problem setting Android tab background color

I'm adding tab icon via selector like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/tab_cart_selected" android:state_selected="true" />
<item android:drawable="#drawable/tab_cart" />
</selector>
http://img844.imageshack.us/img844/2535/questionn.jpg
All is fine, but my icon is smaller then tab itself and I want to set background color same as icon color. But I cant seem to figure out hot to do that.
Any suggestions?
use a .png transparency.
How to Make a Transparent PNG
test with this image and you will see

Categories

Resources