I use this tag to set background
android:background="#drawable/image_name"
how to make that?
There are two ways you can go about changing the transparency of your background image. The first is by modifying the XML layout and the second is programmically.
You can do it in XML by using the code:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/image_name"
android:alpha=".75"/>
Where android:alpha="" is your transparency with 1 as fully solid and 0 is completely transparent. More information is at the Android documentation.
(This will also work with the background of your view if that's what you want)
You can also change the transparency of it programmically (assuming you are using an ImageView).
To do this you can use the following code for the background of your view
int transparency = 100;
mView.getBackground().setAlpha(transparency);
The transparency runs from 0 to 225 where 0 is transparent and 225 is solid.
int transparency = 51 //0-255 (51 is 20% transparent)
nameOfYourView.getBackground().setAlpha(transparency);
Related
How to make background opacity of the View (for ex. EditField )with transparent, infliction, subtraction "Screen" like it is in Photoshop?
I know if I set background to "#android:color/transparent" for EditField then white background will be visible, but not main backgrounf of the layout
I need to implement this one:
You can't do it simply.. not by any code.. the only way to do that is to get a drawable .png image(you need photoshop to create it) that has this shape(semi tranaparent on the frame ans fully transparent inthe center with rounded corners).. make it with small width .. and use 9patch tool for stretching (so you can get flexible width)...
I have an background image set to an ImageView, Now i want to change the opacity of an image without, for that i write this code to change the opacity of ImageView, but when i do so it remove the background image from the image view, So my question is how can i change the opacity of ImageView without removing background image form it.
Code i used is:
ImageView imageView = (ImageView) findViewById(R.id.image_view);
imageView.setBackgroundResource(R.drawable.theme1_page_header); // Set background image
int opacity = 100; // from 0 to 255
imageView.setBackgroundColor(opacity * 0x1000000); // change opacity of image
the most important part of alpha is that the value has to be decimal
0 = transparent and 1 = visible
so 0.5 is half way visible
in the XML you can do
<ImageView
android:layout_width="30dp"
android:layout_height="35dp"
android:id="#+id/imageView"
android:alpha="0.4" // <----------------- this is the fun part
android:layout_alignParentRight="false"
android:background="#drawable/imagename"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_alignWithParentIfMissing="false"
android:layout_marginLeft="100dp"
android:layout_alignParentBottom="false"
android:layout_alignParentStart="false"
android:layout_alignTop="#+id/bar"
android:layout_marginTop="30dp"/>
You can use
imageView.setAlpha(yourValue); // some value 0-255 where 0 is fully transparent and 255 is fully opaque
See the documentation
ImageView imageView = (ImageView) findViewById(R.id.image_view);
Drawable dPage_header= getResources().getDrawable(R.drawable.theme1_page_header);
// setting the opacity (alpha)
dPage_header.setAlpha(10);
// setting the images on the ImageViews
imageView.setImageDrawable(dPage_header);
For Api >=16 . Use setImageAlpha as your practice because setAlpha will be deprecated in coming future. `
ImageView.setAlpha(int) has been renamed to ImageView.setImageAlpha(int) to avoid confusion. See Detail Explanation here
Use this option in layout xml for opacity as well as to turn the Android Material icons from Black to Grey.
android:alpha=0.5
In Kotlin we can change alpha in code like this:
myImageView.alpha = 0.5f
Change alpha value to whatever you want between 0.0f to 1f
Option 1
Use imageView.setAlpha(100).
If you're using Android 2.3 you have to do a horrible hack with a zero-length animation using nineolddroids.
Option 2
Subclass ImageView and override its onDraw() method to draw the image transparently.
Option 3
Actually modify the image pixels using get/setPixel(). This'll be very slow though; there's probably a faster way to do this (e.g. using renderscript).
I want the background of my textView or Linear layout to be translucent. I have attached an image as an example of what I want to achieve.
translucent http://imagecdn3.maketecheasier.com/2011/03/kde-style-oxygen-transparent.jpg
I don't want to make the whole activity translucent but just a layout field in it. How can I get this?
See Translucent theme, descibed here:
http://developer.android.com/guide/topics/ui/themes.html
create an activity
set activity’s theme as “#android:style/Theme.Translucent” in AndroidManifest.xml
that’s all
Check this for more details.
For making the activity Completely transparent,
main.xml-
android:background="#android:color/transparent"
manifest.xml-
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
For making activity Translucent
#00FFFFFF - Full Transparency
#10FFFFFF - 90% Transparency
#20FFFFFF - 80% Transparency
#30FFFFFF - 70% Transparency
#40FFFFFF - 60% Transparency
#50FFFFFF - 50% Transparency
#60FFFFFF - 40% Transparency
#70FFFFFF - 30% Transparency
#80FFFFFF - 20% Transparency
#90FFFFFF - 10% Transparency
#99FFFFFF - 01% Transparency
Usage- in layout.xml,
android:background="20FFFFFF"
here "20" is transparency and "FFFFFF" is color
Get HTML color codes from http://html-color-codes.info/
I am using a linear layout and frame layout. In the linear layout I keep an image as background and in the frame layout I keep an imageView. In that imageView I give an image.
Now I want to make the second image (that is in the imageView) transparent. How can I do this?
Try this:
ImageView myImage = (ImageView) findViewById(R.id.myImage);
myImage.setAlpha(127); //value: [0-255]. Where 0 is fully transparent and 255 is fully opaque.
Note: setAlpha(int) is deprecated in favor of setAlpha(float) where 0 is fully transparent and 1 is fully opaque. Use it like: myImage.setAlpha(0.5f)
android:alpha does this in XML:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/blah"
android:alpha=".75"/>
Set an id attribute on the ImageView:
<ImageView android:id="#+id/myImage"
In your code where you wish to hide the image, you'll need the following code.
First, you'll need a reference to the ImageView:
ImageView myImage = (ImageView) findViewById(R.id.myImage);
Then, set Visibility to GONE:
myImage.setVisibility(View.GONE);
If you want to have code elsewhere that makes it visible again, just set it to Visible the same way:
myImage.setVisibility(View.VISIBLE);
If you mean "fully transparent", the above code works. If you mean "partially transparent", use the following method:
int alphaAmount = 128; // Some value 0-255 where 0 is fully transparent and 255 is fully opaque
myImage.setAlpha(alphaAmount);
If you are in an XML file, use the following to make your imageview transparent!
android:background="#null"
On newer versions of Android (post Android 4.2 (Jelly Bean) at least), the setAlpha(int value) method is depreciated. Instead, use the setAlpha(float value) method that takes a float between 0 and 1 where 0 is complete transparency and 1 is no transparency.
Set transparency using setAlpha(float alpha). The below code works for me were I used an alpha value in float, 0 - 1.
0: Full Transparent
0.5 - 50%: Transparent
1: Full Opaque
ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView);
imageView.setImageResource(mResources[position]);
imageView.setAlpha(.80f);
As setAlpha int has been deprecated, setImageAlpha (int) can be used
ImageView img = (ImageView) findViewById(R.id.img_image);
img.setImageAlpha(127); //value: [0-255]. Where 0 is fully transparent and 255 is fully opaque.
The method setAlpha(int) from the type ImageView is deprecated.
Instead of
image.setImageAlpha(127);
//value: [0-255]. Where 0 is fully transparent and 255 is fully opaque.
In XML, use:
android:background="#android:color/transparent"
Image alpha sets just opacity to ImageView which makes Image blurry, try adding tint attribute in ImageView
android:tint="#66000000"
It can also be done programatically :
imageView.setColorFilter(R.color.transparent);
where you need to define transparent color in your colors.xml
<color name="transparent">#66000000</color>
For 20% transparency, this worked for me:
Button bu = (Button)findViewById(R.id.button1);
bu.getBackground().setAlpha(204);
Use:
ImageView image = (ImageView) findViewById(R.id.image);
image.setAlpha(150); // Value: [0-255]. Where 0 is fully transparent
// and 255 is fully opaque. Set the value according
// to your choice, and you can also use seekbar to
// maintain the transparency.
You can easily do this in your XML file by this code:
android:alpha="0.85"
It will make your image 15% transparent. 0 is fully transparent and 1 is fully opaque
I was just wondering if there was a way to change the opacity of the background image for a View (ie. TextView, etc.).
I know that I can set the background image like this:
android:background="#drawable/my_drawable_image"
Or I can set a specific background colour with an alpha setting like this:
android:background="#10f7f7f7"
Is there a way I can control the opacity (set the alpha) if I'm setting the background as a drawable image? And I want to do this in the XML Layout. I already know that I could grab the Drawable object and programmatically set the alpha, but I want to see if I can do it in the layout.
I ended up just going with the programmatical solution, since it doesn't look like it can be done via the XML layouts.
Drawable rightArrow = getResources().getDrawable(R.drawable.green_arrow_right_small);
// setting the opacity (alpha)
rightArrow.setAlpha(10);
// setting the images on the ImageViews
rightImage.setImageDrawable(rightArrow);
This might make your Work simpler
View backgroundimage = findViewById(R.id.background);
Drawable background = backgroundimage.getBackground();
background.setAlpha(80);
Alpha Values 0-255, 0 means fully transparent, and 255 means fully opaque
from: This Answer
You can also use XML to change the transparency:
android:alpha = "0.7"
The value of alpha ranges from 0 to 1
You can embed the image in xml, so you'll be able to see it in the Graphical Layout
<LinearLayout
style="#style/LoginFormContainer"
android:id="#+id/login_layout"
android:orientation="vertical"
android:background="#drawable/signuphead">
And change the code like this to make it transparent:
Drawable loginActivityBackground = findViewById(R.id.login_layout).getBackground();
loginActivityBackground.setAlpha(127);
The answer you gave didn't exactly answer the question you asked. Here's what I did.
Drawable login_activity_top_background = getResources().getDrawable(R.drawable.login_activity_top_background);
login_activity_top_background.setAlpha(127);
LinearLayout login_activity_top = (LinearLayout) findViewById(R.id.login_activity_top);
login_activity_top.setBackgroundDrawable(login_activity_top_background);