Change background color to tabhost - android

I would like to change the background of the tabwidget in shown in the next image:
I would like to use a different background color, and change the font color to the selected tab. How can I do that?

To do this i used drawables for tab widgets instead of fixed images. my code is
tab1.setImageDrawable(getResources().getDrawable(R.drawable.tab_drawable));
in the tab_drawable is a simple selector defining the behavior of the drawable for different state. you can try that it is very useful.

you can google for the tables available for different colors
this is a chart or table available with color and the code to get that
color
just choose which ever you like

Related

Android Button with border and background color

I am trying to beautify some of the UI components in Android. I need to create a button with black border and background color. Everything is fine if I hardcode the variables into XML. But i have different buttons with different background color and different border color and size and etc. all the variations you could say. And it is surely wrong if I go and create all the variations in separate XML files. At the moment, I am creating styles in code but it looks a little inefficient.
gradient.setColor(getContext().getResources().getColor(R.color.ORANGE));
gradient.setCornerRadius(5);
gradient.setStroke(5, 0xFF000000);
button.setBackground(gradient);
And if I want to have button with different background color, I need to create another gradient and initialize it and set to button's resource. Another thing, when I am setting the background of the button, I am also losing the color change when the button is pressed. How do you create an XML drawable resource that can be customized in the interface? Or what is the easier way?
Thanks.
used this:-
Drawable mDrawable = ContextCompat.getDrawable(youContext, R.drawable.youdrawable)
mDrawable.setColorFilter(PorterDuffColorFilter(youColor, PorterDuff.Mode.MULTIPLY)
button.setbackground(mDrawable)

Default android.R.atrr. for ListView item background color

I know I can use the android.R.attr. for default values (like colors, styles, etc.)
Does anyone know which android.R.atrr. I need to use for the default ListView Item background color?
When I look at the available android.R.atrr. I see there is colorFocusedHighlight, colorLongPressedHighlight, colorMultiSelectHighlight and colorPressedHighlight, but not one for just the item that isn't pressed/focussed/etc.
It's actually a drawable, not a color like I mentioned in my comment.
http://developer.android.com/reference/android/R.drawable.html#list_selector_background

Are there in android vars or constants with colors of color sceme?

Other languages I used to use some constants that named something like "BackgroundColor" or "TextColor". If I want to color my component I just set its color using that constants, and I didn't care what color it was in particular.
For example, I set some color to ColorText and when user changed main color sceme my component will be visible for sure and color will suit this color sceme. And if I will set my color to just Black there may be a circumstance when it just will not be visible.
Is there a color-constants that change inside for different color scemes in android?
No, there's no one BackgroundColor for all etc. But you can get the same effect by using styles and themes. Please developer docs here and example tutorial here

ANDROID : Changing the color of ExpandableListView's group indicator

The problem : I've changed my app's background color to white, and now I cannot see the ExpandableListView's group indicator anymore.
ExpandableListView has methods to change text color, background color, and divider color, but nothing I can see for the group indicator color.
I do not want to provide custom drawables, I just want to change the color of the drawables that are provided by Android, programmatically.
I feel there must be some simple way to do this.
You will have to use custom drawables here. You can't change the android drawables provided by Android.

How to change text style based on state with XML?

StateListDrawables and <selector> are great for setting different drawables for each state of a view, but is there a way to tie in what text style that view should use for each of those states?
For example, if you had a button that was white with black text, and when clicked, the button color became black, you would want your text color to change to white. I can imagine how I would do this with code, but is there a way to do it with XML similar to the <selector> used for drawables?
Well there sort of is. I don't believe there is a way to say, something like state_focused use Bold or italics or fontSize = 20. But there are ways to change the color. So using the selector mechanic you can create a ColorStateList
http://developer.android.com/reference/android/content/res/ColorStateList.html
Basically you do the same thing as you would a state list drawable using a selector except that you can place a color inside the individual items. Then you save your XML inside the color folder.
/res/values/color/my_stateful_color.xml
and set the android:textColor to "#color/my_stateful_color"

Categories

Resources