Can you add custom states to Android TextViews? - android

I'm looking to add new states to a TextView. I chose TextViews because they're a relatively simple controls and I want use this in a widget so I really want to cut down on nested controls as much as possible. I need to define custom states for my TextViews. States like, not_started, in_progress, completed, missed, did_not_do, etc...
I want the background and font color to change with the states. How can I do this?

I can use a Level-List selector to handle my "custom states" and define my states as integers.
http://developer.android.com/reference/android/graphics/drawable/LevelListDrawable.html

Related

How to color a portion of a view in android?

Now I have this task where I should create a rating bar just like youtube in my app , and so my idea was to have a textview where I set its background to a color but then remove the color according to an equation I will make so it displays only a percentage of it... any idea how can I do this or where to look ?
The simplest way to do this would be to create a selector.xml. You would assign android:background="#drawable/selector". Your selector would decide which background color to show based on what percentage you have assigned.
This link explains how to use selectors with buttons. It should help to get you on the right track...http://developer.android.com/guide/topics/resources/color-list-resource.html
EDIT: You can still accomplish a custom progress bar by xml. It is very similar to the selector. Just think of it as many more selectors based on progress instead of state. Here is a nice example...Custom Drawable for ProgressBar/ProgressDialog
You can also look into xml animations. They are similar.

Create custom button based on Android style

I need to create a custom button control that will inherit from the same Android style as all other buttons in my application. However, I want to be able to add several lines of text where some characters of the text will be in different colors. Is there anyway to achieve this, I can't seem to see a way?
Currently I have created a view that looks like a button by drawing the background, this is ok but I want the background etc to change with the application style.
You should make your button descend from the generic theme for Widget.Button. This way you can ensure that all the default settings will come through for you.

Android UI: setting background color for Button prevents it from highlighting upon press

I need to eliminate the gap between buttons in a layout. I'm doing it by setting background color for a style and applying that style to my buttons. This eliminates the highlighting upon press, which I of course need. Here is a solution to this problem, but it requires extra actions to be taken with Java code. Can I make it statically, only with XMLs?
Also, if there is any other way to remove the gap without changing the other aspects of button's appearance - please suggest. The only requirement is it should be done with XML (however, if no other options exist, I can inherit Button class).
You can use StateList xml for background of your button

How to design custom list view in android?


			
				
Plenty of tutorials on the web for that:
http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
http://www.josecgomez.com/2010/05/03/android-putting-custom-objects-in-listview/
http://androidguys.com/2008/07/14/fancy-listviews-part-one/
For that particular case, my guess is that, next to the icon, there is a RelativeLayout with three TextViews, and using a custom background drawable. That drawable will define different background colors with a selector depending on the android:state_selected and/or android:state_pressed states.

Android:How can i change the color of the text of the ListAdapter?

The default color of the text is white. Let's say if i want to change the color, then how can i do it? Any clue?
in the getView method, find your TextView and set the color via setTextColor().
If you want your color changed for you based on the state of the item ( selected/focused etc) create new color in my_color.xml and define your states - examples of stateful colors are in SDK in res folders.
I highly recommened writing your own theme for the list view and then setting it in the layouts xml file, this means that you can use the same style throughout your app
This is a good tutorial to start with
http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/
One thing you could do is use your own layout for the list items. This way you could set whatever color or any other layout in the items.
You couldn't use setTextColor(); in your ListAdapter ? I think you could

Categories

Resources