In my Android app, I'm trying to get buttons to be tinted a certain color (either blue, red or gold). The default button tint is grey. Does anyone know how to change the color of the button so that the transparency remains with it?
I tried using:android:background
but that ditches the transparency completely and makes the button one solid color.
I also tried using:android:#color/transparent
but that ditches the color completely in favor of a fully transparent button. I've looked online for a while and found mostly stuff relating to image buttons. The kind that I'm trying to tint is just the standard Button buttons. I'm also guessing that this can be done mostly just through XML. Is that correct?
You could try and create your own button drawable like so...
Take the button drawable from the Android SDK ([ANDROID_SDK_HOME]/platforms/data/res) and import the drawables into your project. Then create a layer list with the button drawable on the bottom and a semi-transparent color on top.
Related
How do you add a shadow on a button with your own colour? The button is set on a gradient background and I have various buttons that require shadows (preferably different colours). Can this be done or if not, how would I create a standard shadow?
I need to change (better also color in area) any color on WebView with transparent.
It must work like AvoidXfermode (I can't use it because of deprecated)
Example:
I have red background and some dive with black color, I need to change this black color with transparent color and make a "hole" in WebView. In this hole, I must see any View what located behind the WebView.
Please help anybody ...
I have a menu, with several buttons and its drawables. This menu is included in 4 activitys.
I am setting the drawable color programmatically:
mDrawable.setColorFilter (0xff0099cc, PorterDuff.Mode.SRC_IN);
The first button by default is enabled, so the color is changed programmatically. When I press another button to go to another activity, the other button changes the color, but the first one remains as if it had activated.
You are not clear about your drawable and so I ll give generic solution to you.
You can just use Drawable.setColorFilter( 0xffff0000, Mode.MULTIPLY ). If you could make the entire image WHITE (FFFFFF) so that when you do PorterDuff.Mode.MULTIPLY, you end up with the correct colors. Note this would not affect the transparent pixels.
For solid images, it is best to use the color filter PorterDuff.Mode.SRC_ATOP because it will overlay the color on top of the source image, allowing you to change the color to the exact color you are looking for.
Let me know, whether it helps.
I have being playing around with the ListView of XYPlots. I was able to change background either by using style="#style/APDefacto.Light" or style="#style/APDefacto.Dark". These two work well but, I want my graph to have complete white background instead of a light or dark background.
Screenshot with the light background.
If you look carefully at the graph, you will see that the background has a grey color but the graph itself is white. I want the whole background to be completely white.
I have try the solution of the link Change the background color of XYplot in android to white?. But that only have the effect of removing the square on the graph but no change is seen on the background.
Below is the resulting screenshot.
Any clues,
Thanks.
Just add these attrs to your XYPlot's xml:
ap:backgroundColor="#FFF"
ap:graphBackgroundColor="#FFF"
I'm trying to achieve buttons similar to the icons in the Action Bar, i.e. transparent images that change background colour on click.
These are the conditions I'd like to satisfy:
Background colour changes on click
Contains a small rectangle shape in the center
Rectangle can change colour programmatically
I tried using a Drawable to represent the rectangle and then to set it as the background of the button, but it expanded to the edges of the button and so there was no background colour to change when clicked (I was able to use drawable.setColorFilter() and button.setBackground(drawable) to alter its colour however). Shrinking the button also shrank the touch-target.
I also tried using a StateListDrawable containing two rectangle shapes, a background and an inner rectangle, so on state_pressed the background rectangle would change colour. However the front rectangle stretched again and completely covered he background rectangle.
Which method can achieve my conditions? Thanks.
Have 2 images for the state of the buttons and use this:
boolean clicked = false
Button btn = (Buttton)findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
if (clicked)
{
clicked = false;
btn.setBackgroundResource(R.drawable.button_image_on);
}
else
{
clicked = true;
btn.setBackgroundResource(R.drawable.button_image_off);
}
}
});
This talk from Google IO 2013 on Android UI design by Nick Butcher and Roman Nurik helped to solve the problem.
The XML attribute style="?android:borderlessButtonStyle" can be set on an ImageButton (or even just a Button) to give it a transparent background which lights up in a standard Holo blue colour on touch. According to Roman Nurik, this attribute provides the standard styling "all for free".
I created an ImageButton containing that borderless button attribute in my layout.xml file, then I created my coloured Drawable in Java and put it inside the button using myImageButton.setImageDrawable(myColouredDrawable); to fit all three of my conditions.
Edit July 2013: To bring the ActionBar pattern to older versions of Android using Jake Wharton's ActionBarSherlock, use style="#style/Widget.Sherlock.ActionButton", or if using the ActionBarCompat Support Library, use style="#style/Widget.AppCompat.ActionButton"
Update May 2017: For ImageViews (I believe it is actually an ImageViewCompat) I am using android:background="?android:attr/selectableItemBackground" on Jellybean onwards.