Default Eclipse Theme for Android Development Spinners? - android

The color of my Spinner widgets change from phone to phone based on there settings,I would like to keep them the same between all phones and I would like to have it be the default eclipse uses in its emulators the color is silverish. Can you please let me know how to apply this specific theme to my Spinner in xml. Thanks in advance.

download the images used in for the spinner from the android source code: spinner_press.9.png, spinner_select.9.png, spinner_normal.9.png then create selector using those.
this is the default selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/spinner_press" />
<item android:state_pressed="false" android:state_focused="true"
android:drawable="#drawable/spinner_select" />
<item android:drawable="#drawable/spinner_normal" />
</selector>

You don't need to create a theme. Just apply a background of your choice to the spinner, as with any other View.
If you want to have different backgrounds you can use a (See here for more info)
For an example of an implementation, nothing better than the android source: https://android.googlesource.com/platform/frameworks/base/+/froyo-release/core/res/res/drawable/spinner_background.xml
You can get the actual 9-patch files from there also (and choose which version you would like to use).

Related

android - Set Switch Off color [duplicate]

The switch widget introduced in API 14 is styled by default with holo theme.
I want to style it slightly different, changing its colors and shape a bit for branding reasons. How does one go about this? I know it must be possible, as ive seen the difference between default ICS and Samsung's touchwiz theme
I assume I'll need some state drawables, and I've seen a few styles in http://developer.android.com/reference/android/R.styleable.html with Switch_thumb and Switch_track that look like what I might be after. I just don't know how to go about using them.
I'm using ActionbarSherlock if that makes a difference. Only devices running API v14 or above will be able to use a switch at all, of course.
You can define the drawables that are used for the background, and the switcher part like this:
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="#drawable/switch_thumb"
android:track="#drawable/switch_bg" />
Now you need to create a selector that defines the different states for the switcher drawable.
Here the copies from the Android sources:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#drawable/switch_thumb_disabled_holo_light" />
<item android:state_pressed="true" android:drawable="#drawable/switch_thumb_pressed_holo_light" />
<item android:state_checked="true" android:drawable="#drawable/switch_thumb_activated_holo_light" />
<item android:drawable="#drawable/switch_thumb_holo_light" />
</selector>
This defines the thumb drawable, the image that is moved over the background. There are four ninepatch images used for the slider:
The deactivated version (xhdpi version that Android is using)
The pressed slider:
The activated slider (on state):
The default version (off state):
There are also three different states for the background that are defined in the following selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#drawable/switch_bg_disabled_holo_dark" />
<item android:state_focused="true" android:drawable="#drawable/switch_bg_focused_holo_dark" />
<item android:drawable="#drawable/switch_bg_holo_dark" />
</selector>
The deactivated version:
The focused version:
And the default version:
To have a styled switch just create this two selectors, set them to your Switch View and then change the seven images to your desired style.
It's an awesome detailed reply by Janusz. But just for the sake of people who are coming to this page for answers, the easier way is at http://android-holo-colors.com/ (dead link) linked from Android Asset Studio
A good description of all the tools are at AndroidOnRocks.com (site offline now)
However, I highly recommend everybody to read the reply from Janusz as it will make understanding clearer. Use the tool to do stuffs real quick
You can customize material styles by setting different color properties.
For example custom application theme
<style name="CustomAppTheme" parent="Theme.AppCompat">
<item name="android:textColorPrimaryDisableOnly">#00838f</item>
<item name="colorAccent">#e91e63</item>
</style>
Custom switch theme
<style name="MySwitch" parent="#style/Widget.AppCompat.CompoundButton.Switch">
<item name="android:textColorPrimaryDisableOnly">#b71c1c</item>
<item name="android:colorControlActivated">#1b5e20</item>
<item name="android:colorForeground">#f57f17</item>
<item name="android:textAppearance">#style/TextAppearance.AppCompat</item>
</style>
You can customize switch track and switch thumb like below image by defining xml drawables. For more information http://www.zoftino.com/android-switch-button-and-custom-switch-examples
Alternative and much easier way is to use shapes instead of 9-patches.
It is already explained here:
https://stackoverflow.com/a/24725831/512011

Android:How to change the draghandle in a listview?

android:fastScrollEnabled="true"
which workes fine but the drag handle which appears is very ugly and i need to change it..
is their any direct method to change the image of the draghandle to something i want ??
If not what should be done?
Note:I am not asking for code,just guide me through it.Thank You.
It's just an image, so you can easily change it.
Add something like that to you application theme :
<item name="android:fastScrollThumbDrawable">#drawable/apptheme_fastscroll_thumb_holo</item>
Which refers to a drawable with 2 states :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/apptheme_fastscroll_thumb_pressed_holo" />
<item android:drawable="#drawable/apptheme_fastscroll_thumb_default_holo" />
</selector>
You can see an examle of what the drawable should be here : Android Holo Colors (enable Fast Scrool at the end of the list). It will look like that :

How can I style an Android Switch?

The switch widget introduced in API 14 is styled by default with holo theme.
I want to style it slightly different, changing its colors and shape a bit for branding reasons. How does one go about this? I know it must be possible, as ive seen the difference between default ICS and Samsung's touchwiz theme
I assume I'll need some state drawables, and I've seen a few styles in http://developer.android.com/reference/android/R.styleable.html with Switch_thumb and Switch_track that look like what I might be after. I just don't know how to go about using them.
I'm using ActionbarSherlock if that makes a difference. Only devices running API v14 or above will be able to use a switch at all, of course.
You can define the drawables that are used for the background, and the switcher part like this:
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="#drawable/switch_thumb"
android:track="#drawable/switch_bg" />
Now you need to create a selector that defines the different states for the switcher drawable.
Here the copies from the Android sources:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#drawable/switch_thumb_disabled_holo_light" />
<item android:state_pressed="true" android:drawable="#drawable/switch_thumb_pressed_holo_light" />
<item android:state_checked="true" android:drawable="#drawable/switch_thumb_activated_holo_light" />
<item android:drawable="#drawable/switch_thumb_holo_light" />
</selector>
This defines the thumb drawable, the image that is moved over the background. There are four ninepatch images used for the slider:
The deactivated version (xhdpi version that Android is using)
The pressed slider:
The activated slider (on state):
The default version (off state):
There are also three different states for the background that are defined in the following selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#drawable/switch_bg_disabled_holo_dark" />
<item android:state_focused="true" android:drawable="#drawable/switch_bg_focused_holo_dark" />
<item android:drawable="#drawable/switch_bg_holo_dark" />
</selector>
The deactivated version:
The focused version:
And the default version:
To have a styled switch just create this two selectors, set them to your Switch View and then change the seven images to your desired style.
It's an awesome detailed reply by Janusz. But just for the sake of people who are coming to this page for answers, the easier way is at http://android-holo-colors.com/ (dead link) linked from Android Asset Studio
A good description of all the tools are at AndroidOnRocks.com (site offline now)
However, I highly recommend everybody to read the reply from Janusz as it will make understanding clearer. Use the tool to do stuffs real quick
You can customize material styles by setting different color properties.
For example custom application theme
<style name="CustomAppTheme" parent="Theme.AppCompat">
<item name="android:textColorPrimaryDisableOnly">#00838f</item>
<item name="colorAccent">#e91e63</item>
</style>
Custom switch theme
<style name="MySwitch" parent="#style/Widget.AppCompat.CompoundButton.Switch">
<item name="android:textColorPrimaryDisableOnly">#b71c1c</item>
<item name="android:colorControlActivated">#1b5e20</item>
<item name="android:colorForeground">#f57f17</item>
<item name="android:textAppearance">#style/TextAppearance.AppCompat</item>
</style>
You can customize switch track and switch thumb like below image by defining xml drawables. For more information http://www.zoftino.com/android-switch-button-and-custom-switch-examples
Alternative and much easier way is to use shapes instead of 9-patches.
It is already explained here:
https://stackoverflow.com/a/24725831/512011

How to apply shadow color to Android EditText when focused?

I have an EditText control in my application and when it is focused (i.e. I'm ready to enter something) I want to apply shadow color to it. How can I do this?
Thanks,
#nagaraju.
You can use the Selector tag like Follows:
Create a New xml file and place it in your drawable folder and name it as shadow_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="#drawable/ask_footer"/>
<item android:state_focused="false" android:state_pressed="true" android:drawable="#drawable/askfooter_hover" />
<item android:drawable="#drawable/ask_footer" />
</selector>
And then go to that xml in which your EditText is declared:
And write one attribute in editText
android:background="#drawable/shadow_color"
and you are done.
Use a selector for your background drawable and create your own nine patches.
does shadow color mean you want a shadow theme background for your view??
then, assuming that you are using xml layout,the GU interface version shown on eclipse allows you to select a particular theme for your view,which i think is what you want.
if you want to put it manually,
you must mention it in the android manifest
eg.
<activity android:name=".activity_name here"android:theme="#android:style/Theme.Dialog">//there are a handful of effects provided by SDK
</activity>
i suggest the graphical user interface method,its easy and you can see the effect as you select the theme
You can also check whether your EditText isFoucsed or not. And if true so change its background image to shadow like image.

Fixed: "Android: Detecting focus/pressed color"

I'm trying to detect the focus/pressed color for button and other elements.
This is needed because I'm developing new components and it's important that those look as part of platform.
Those colors are ORANGE on android sdk and GREEN on HTC SenseUI.
If I could detect that color my component will look as part of platform on both version.
Does anyone knows how to do this?
It's possible to create "selector" which uses custom image for default state and platform default for focus/selection.
To do this follow the steps:
1) create xml file with selector in "res/drawable" (e.g. "red_button.xml"):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#android:drawable/btn_default" >
</item>
<item android:state_focused="true"
android:drawable="#android:drawable/btn_default" >
</item>
<item
android:drawable="#drawable/btn_default_red" >
</item>
</selector>
2) from folder ".../android-sdk-mac/platforms/android-1.5/data/res/drawable/" take picture "btn_default_pressed.9.png" and change color as you like (I needed to change it to red and for this GIMP is enough).
3) place altered picture in "res/drawable" (e.g. with name "btn_default_red.9.png")
4) define button:
<Button
android:id="#+id/info_button"
android:layout_width="wrap_content"
android:layout_height="37dip"
android:layout_marginTop="1dip"
android:background="#drawable/red_button"
android:text="[Info]" />
That's all.
This is result:
alt text http://img200.imageshack.us/img200/1349/custombutton.png
I had this problem too. As already stated, the problem is that the backgrounds aren't simple colors, they're Drawables that could take on all kinds of appearances. However, I found a work-around that may help. If your custom component looks something like an existing one, e.g. a Button or ListView entry, you can just steal their background/selector and set that as the background for your custom component. E.g., in your custom component constructor:
setBackgroundDrawable(new Button(context).getBackground());
or for a background more suitable for list-like components:
setBackgroundDrawable(new ListView(context).getSelector());
You may want to optimise that code somewhat, but you get the idea.
Those aren't colors. They are a few nine-patch images out of a StateListDrawable. I am skeptical that there will be a reliable way for you to determine what the color is, one that will work across all devices and all versions of Android.
This is pretty much a duplicate of: Android ListView Selector Color
Also, why do you need to detect the colours? Just do nothing and your widgets will fit in to the platform's existing look & feel.
Or if you're writing a custom theme, just make yours inherit from android:Theme.

Categories

Resources