hexidecimal code for 10% transparency in android? - android

Id like to take a black background color and give it 10% opacity, what is the hexidecimal code for this in android?

0xAARRBBGG, AA is the alpha channel which determines transparency. 00 is fully transparent, FF is fully opaque. 10% would be about 0x19.

Related

Default Alpha value of navigation bar in Lollipop

If you set android:windowTranslucentNavigation to true in your theme in Lollipop the navigation bar won't be fully translucent like in KitKat. Instead it's a dark semi-transparant background. Does anyone here know what the alpha value is of that background?
I've made some test with navigation bar and found that alpha of navBar when android:windowTranslucentNavigation = true is 40% of black color.
So color in hex would be: #66000000
Here is steps how I calculated this value:
I made screenshot as presented below
Then I open it in Gimp image editor and take RGB values of each color
White is (255,255,255), white under navBar (153,153,153)
Grey is (150,150,150), grey under navBar (90,90,90)
Then I calculate as next:
255 is 100%
153 is x
x = 153 * 100 / 255 = 60%
So I calculated invert value of alpha channel, the true value of alpha channel is 100 - 60 = 40%
ARGB value of 40% is (102,0,0,0) in hex it's #66000000

What does the number next to a color mean?

I'm reading this article about material design. In the list of colors, there is a number next to each color that seems to darken the color as its value goes up.
What does this number means, more precisely?
Edit: As all the answers are about the hex values, I'm adding this edit to clarify the question. My question is about the left hand side numbers like 700, 500, ... not the hex numbers (#3f51b5, ...)
Edit 2: In RGB model, each of the Red, Green or Blue can have a value in scale of 0 - 255. 0 means lack of the color and 255 means the color exists in full power. Is there a numerical meaning for the left hand side numbers? Can I calculate the '700' of a color, assuming '500' of it is #3F51B5? Or these numbers are just name for different shades of color in a palette?
Those values are the relative lightness/darkness or "tint" of the color, where 50 is lightest and 900 is darkest. The Material Design guidelines suggest using the 500 tint as your primary color and the 700 tint as the darker status bar color.
The Annn values are if you're using the color as your accent color.
See https://www.google.com/design/spec/style/color.html#color-ui-color-application
The other answers are correct as well, but I think you are asking about the left hand side numbers. You can use these to specify your theme colors in Angular-Material.
$mdThemingProvider.theme('default')
.primaryPalette('purple', {
'default': '700', // by default use shade from the palette for primary intentions
'hue-1': 'A400', // use shade for the <code>md-hue-1</code> class
'hue-2': '600', // use shade for the <code>md-hue-2</code> class
'hue-3': 'A100' // use shade for the <code>md-hue-3</code> class
})
// If you specify less than all of the keys, it will inherit from the default shades
.accentPalette('deep-purple', {
'default': '200' // use shade 200 for default, and keep all other shades the same
})
The numbers you see in use, correspond the left hand side numbers to set up colors. My site is using variations of the purple theme in this example, and I can set the hue's different from what the Google settings were.
The numbers refer to the darkness of a shade variant (inverse of HSL lightness). The numbers use a scale of 0 to 1000, where 0 is white and 1000 is black.
From the Android documentation for R.color:
system_accent1_0
Lightest shade of the accent color used by the system. White.
system_accent1_10
Shade of the accent system color at 99% lightness.
system_accent1_100
Shade of the accent system color at 90% lightness.
And so on.
The general formula is shadeVariant = 1000 - (lightness * 1000).
(The one curious exception is that the 500 shade variant uses 49% lightness instead of 50%, but this is probably an implementation detail that could be ignored when re-implementing.)
Knowing the formula should additionally make it easy to calculate these values directly. For example, using Polished, you would be able to setLightness(accent, 0.9) to calculate the 100 shade variant of an accent colour yourself in a Node.js app. From there it would be easy to build a utility function that can generate any variant of any colour.
I found some information in this angular.io guide to theming:
In Material Design, each hues in a palette has an identifier number. These identifier numbers include 50, and then each 100 value between 100 and 900. The numbers order hues within a palette from lightest to darkest.
There you have it, the answer to your question: Those numbers are just static identifiers.
As an example of how they can be used, this guide to "Reading hues from palettes" states:
You can use the get-color-from-palette function to get specific hues from a palette by their number identifier.
#use '~#angular/material' as mat;
$my-palette: mat.define-palette(mat.$indigo-palette);
.my-custom-style {
background: mat.get-color-from-palette($my-palette, '500');
color: mat.get-color-from-palette($my-palette, '500-contrast');
}
The number which you are seeing is the HEX (hexadecimal) values for the color tone and the color. You can use it in CSS files instead of writing i.e. black, white or blue.
From WIKI:
"A hex triplet is a six-digit, three-byte hexadecimal number used in HTML, CSS, SVG, and other computing applications to represent colors. The bytes represent the red, green and blue components of the color. One byte represents a number in the range 00 to FF (in hexadecimal notation), or 0 to 255 in decimal notation"
More about it here https://en.wikipedia.org/wiki/Web_colors
The number is codes given to each and all colorssupported by the system. Eachh color code contains symbol "#" and 6 letters or numbers. These numbers are in hexadecimal numeral system. For example "FF" in hexadecimal represents number 255 in Decimal.
Meaning of symbols:
The first two symbols in HTML color code represents the intensity of red color. 00 is the least and FF is the most intense. The third and fourth represents intensity of green and fifth and sixth represents the intensity of blue. So with combining the intensity of red, green and blue we can mix almost any color that our heart desire.
Examples:
#FF0000: With this HTML code we tell browser to show maximum of red and no green and no blue. The result is of course pure red color.
#00FF00 - This results in pure green.

Android - How to set color value to TRANSPARENT

how to get parseColor color value to transparent.
mPaint.setColor(Color.parseColor("#FFFF00"));
thanks for help
Suppose your preferred color is red #FF0000
Adding 00 in the beginning will make it 100% transparent and adding FF will make it 100% solid.
So, 100% transparent color is: #00ff0000
and 100% solid color is: #ffff0000
And any value in between 00 to ff can be used to adjust the transparency.
just used android color string
mPaint.setColor(getResources().getColor(android.R.color.transparent));
You can use Color.TRANSPARENT if you do not want to change the transparency level.
import android.graphics.Color;
// use Color.TRANSPARENT
mPaint.setColor(Color.TRANSPARENT);
https://developer.android.com/reference/android/graphics/Color#TRANSPARENT
You can use Color.argb(int alpha, int red, int green, int blue)
Alpha corresponds to transparency. 0 for fully transparent. 255 for opaque.
http://developer.android.com/reference/android/graphics/Color.html#argb(int,%20int,%20int,%20int)
Return a color-int from alpha, red, green, blue components. These
component values should be [0..255], but there is no range check
performed, so if they are out of range, the returned color is
undefined.

Possible to set transparency to XML gradient file?

Is it possible to set transparency in gradient which is set in the XML file?
Say you have a gradient with 2 colors:
StartColor #111111
EndColor #333333
Adding transparency is as simple as adding 2 HEX digits to the beginning of each color
SO:
If you want the StartColor (for example) to be 100% opaque:
change its value to #FF111111
If you want the EndColor (for example) to be 100% transparent:
change its value to #00333333
You can of course use values between 00 and FF for transparency if you don't want the extreme values.
The values between HEX 00 and FF are values between 0 and 255 in normal numbers:
To transform from [0,255] to [00,FF]:
Open calculator in windows and change mode to scientific
There are options like : Dec, Hex, Oct ...
Choose Dec and type the number between 0 and 255
Choose Hex and the number will become in hex between 00 and FF
You should be able to use #AARRGGBB format for the start/end colors, with the AA portion specifying the alpha channel (i.e., transparency).

Set transparent background of an imageview on Android

I am using a web view in which I am adding an image view. How can I set the background of this image view to transparent?
I have tried this:
mImageview.setBackgroundResource(R.color.trans);
Where trans → <color name="trans">#00000000 </color>.
You can set the background transparent of any layout, any view, or any component by adding this code in XML:
android:background="#android:color/transparent"
In your XML set the Background attribute to any colour, White(#FFFFFF) shade or Black(#000000) shade. If you want transparency, just put 80 before the actual hash code:
#80000000
This will change any colour you want to a transparent one.. :)
In addition to what Harshad mentioned:
Two hexadecimal characters can be appended to any hexadecimal color code. The first two characters in an 8-digit hex color code represents its opacity in Android.
The two hexadecimal characters can range from 00 to FF. For example,
Normal opaque black hex- "#000000"
Fully transparent - "#00000000"
Fully opaque - "#FF000000"
50% transparent - "#7F000000"
This way you can change any color to any level of transparency.
To find the hexadecimal prefix from a percentage:
Divide the percentage number by 100 and multiply by 255 to get the decimal value. Convert the decimal to hexadecimal here.
For example, for 50%, 50/100 * 255 = 127. Using the link we get hexadecimal value 7F.
Source: Android: how to create a transparent or opaque background
If you want to add 20% or 30% transparency, you should pre-pend two more characters to the hexadecimal code, like CC.
Note
android:background="#CCFF0088" in XML
where CC is the alpha value, FF is the red factor, 00 is the green factor, and 88 is the blue factor.
Some opacity code:
Hex Opacity Values
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00
You can also set opacity programmatically like:
yourView.getBackground().setAlpha(127);
Set opacity between 0 (fully transparent) to 255 (completely opaque). The 127.5 is exactly 50%.
You can create any level of transparency using the given formula. If you want half transparent:
16 |128 Where 128 is the half of 256.
|8 -0 So it means 80 is half transparent.
And for 25% transparency:
16 |64 Where 64 is the quarter of 256.
|4 -0 So it means 40 is quarter transparent.
Use the below code for black:
<color name="black">#000000</color>
Now if you want to use opacity then you can use the below code:
<color name="black">#99000000</color>
And the below for opacity code:
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00
There is already a predefined constant. Use Color.TRANSPARENT.
There is already a transparent built into Android: R.color.transparent. http://developer.android.com/reference/android/R.color.html#transparent
But I think you may want to make the background of the image that you are placing into the WebView transparent, for example, with a transparent PNG, rather than the ImageView background. If the actual image is not at all see-through then the ImageView background can't be seen through it.
Try this code :)
Its an fully transparent hexa code - "#00000000"
In case you want it in code, just:
mComponentName.setBackgroundColor(Color.parseColor("#80000000"));
In your XML file, set an attribute "Alpha"
such as
android:alpha="0.0" // for transparent
android:alpha="1.0" // for opaque
You can give any value between 0.0 to 1.0 in decimal to apply the required transparency. For example, 0.5 transparency is ideal for disabled component
Or, as an alternate, parse the resource ID with the following code:
mComponentName.setBackgroundColor(getResources().getColor(android.R.color.transparent));
In xml
#android:color/transparent
In code
mComponentName.setBackgroundResource(android.R.color.transparent)
In Android Studio it is very simple to adjust color and opacity using a built-in tool:
For those who are still facing this problem, you may try this
element.getBackground().setAlpha(0);
One more simple way:
mComponentName.setBackgroundResource(android.R.color.transparent);
Use the following for complete transparency:
#00000000
When I tried with #80000000 I got a black transparent overlay which I don't want. Try to change the first two digits; it controls the level of transparency, like
#00000000
#10000000
#20000000
#30000000
Another working option I came across is to set android:background="#null"
You could also use View.setAlpha(float) to change the visibility precisely.
0 would be transparent, 1 fully visible. ;)
Try to use the following code. It will help you in full or more.
A .xml file designed to use this code to set background color:
android:background="#000000"
or
android:background="#FFFFFF"
Or you can set it programmatically as well.
Also you can use this code programmatically:
image.setBackgroundDrawable(getResources().getDrawable(
R.drawable.llabackground));
Also this code for setting the background color as well programmatically:
image.setBackgroundColor(Color.parseColor("#FFFFFF"));
This code for the same programmatically:
image.setBackgroundColor(getResources().getColor(Color.WHITE));
The color depends on your choice of which color you want to use for transparent. Mostly use a white or #FFFFFF color.
Regarding R.drawable.llabackground: This line of code is for your style of the background, like something special or different for your purpose. You can also use this.
If you use a drawable XML image you can make it transparent as shown in the picture below, or you can use a color code:
<color name="black">#99000000</color>
Color definitions with transparency information may be in the form
#AARRGGBB or #ARGB.
You can use also the shorter value for full transparency:
#0000.
Other values are e.g.:
white grey black
#FFFF #F888 #F000 - full color
#EFFF #E888 #E000
#DFFF #D888 #D000
#CFFF #C888 #C000
#BFFF #B888 #B000
#AFFF #A888 #A000
#9FFF #9888 #9000
#8FFF #8888 #8000
#7FFF #7888 #7000
#6FFF #6888 #6000
#5FFF #5888 #5000
#4FFF #4888 #4000
#3FFF #3888 #3000
#2FFF #2888 #2000
#1FFF #1888 #1000
#0FFF #0888 #0000 - full transparency
ImageView.setBackground(R.drawable.my_background);
ImageView.setBackgroundResource(R.color.colorPrimary);
ImageView.getImageAlpha();
ImageView.setAlpha(125); // transparency
Try this:
#aa000000
For transparency 000000 = black, you can change these six numbers for the color you want.
use RelativeLayout which has 2 imageViews in . and set transparency code on the top imageView.
transparency code :
<solid android:color="#color/white"/>
<gradient android:startColor="#40000000" android:endColor="#FFFFFFFF" android:angle="270"/>
Convert Percentage to hex using any online tool & than simply add it on front of color value
Example: using https://www.joshuamiron.com/percent-to-hex-converter
80% opacity would be
<color name="opaque_80_percent">#CC000000</color>

Categories

Resources