Making a android button’s background translucent, - android

Is there a way to make an android button’s background translucent within xml code,
So the button has no background drawable?

android:background="#android:color/transparent"
You can also set your own colors:
android:background="#80000000"
The first two hex characters represent opacity. So #00000000 would be fully transparent. #80000000 would be 50% transparent. #FF000000 is opaque.
The other six values are the color itself. #80FF8080 is a color I just made up and is a translucent sort of pinkish.

The best way is to create a selector.

Set the background to the standard android transparent color.
In Code:
myButton.setBackground(getResources().getColor(android.R.color.transparent));
In xml:
android:background="#android:color/transparent"

Related

MPAndroidChart - Set a background image [duplicate]

I'm using the amazing library MPAndroidChart. It works like a charm, except when I'm trying to change the background color of the BarData. Default color is white, and I want to change it to Transparent.
I've tried this :
Paint p1 = mChart.getPaint(Chart.PAINT_GRID_BACKGROUND);
p1.setColor(Color.RED);
and this:
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
... but it seems that doesnt works.
Any ideas ?
Thanks =)
Since release v1.6.5, the background of the Chart is transparent by default. Meaning, that everything in the background (chart background, other Views, etc.) that is not overlayed by data drawn into the Chart, will be visible.
If you want to change the background (color, or maybe drawable), you can either do that by changing the chart-background
in .xml (android:background="...")
by calling setBackgroundColor(...) or setBackgroundResource(...)
Another way could be to change the background of the parent layout that contains the Chart.
Code to change Background color:
chart.setBackgroundColor(Color.TRANSPARENT); //set whatever color you prefer
chart.setDrawGridBackground(false);// this is a must
if you want to Change Whole Screen Background Color
Barchart chart;
chart.setBackgroundColor(Color.rgb(0, 0, 0));//Set as a black
chart.setDrawGridBackground(false);//set this to true to draw the grid background, false if not
Happy to help Thanks
So, after some research, I've found that it's not possible yet: https://github.com/PhilJay/MPAndroidChart/issues/53
Hope It will be possible soon ! =)

How to change chart background with MPAndroidChart library?

I'm using the amazing library MPAndroidChart. It works like a charm, except when I'm trying to change the background color of the BarData. Default color is white, and I want to change it to Transparent.
I've tried this :
Paint p1 = mChart.getPaint(Chart.PAINT_GRID_BACKGROUND);
p1.setColor(Color.RED);
and this:
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
... but it seems that doesnt works.
Any ideas ?
Thanks =)
Since release v1.6.5, the background of the Chart is transparent by default. Meaning, that everything in the background (chart background, other Views, etc.) that is not overlayed by data drawn into the Chart, will be visible.
If you want to change the background (color, or maybe drawable), you can either do that by changing the chart-background
in .xml (android:background="...")
by calling setBackgroundColor(...) or setBackgroundResource(...)
Another way could be to change the background of the parent layout that contains the Chart.
Code to change Background color:
chart.setBackgroundColor(Color.TRANSPARENT); //set whatever color you prefer
chart.setDrawGridBackground(false);// this is a must
if you want to Change Whole Screen Background Color
Barchart chart;
chart.setBackgroundColor(Color.rgb(0, 0, 0));//Set as a black
chart.setDrawGridBackground(false);//set this to true to draw the grid background, false if not
Happy to help Thanks
So, after some research, I've found that it's not possible yet: https://github.com/PhilJay/MPAndroidChart/issues/53
Hope It will be possible soon ! =)

background color of custom notification with image buttons is black in 3.1 emulator

I have custom notification with linear layout that contains four image buttons.
I set the linear layout background color to transparent color #00000000 and also i set the background color of the four image buttons to transparent color #00000000.
As Expected, According to the transparent color of linear layout and image buttons, my custom notification background color must match the emulator notification background color(almost gray).
but actually the background of notification is still black.
My minimum sdk is 11 and target is 19
Note that the other previous questions not solved my problem.
Thanks in advance, Mostafa.
Try to use in your XML file
android:background="#android:color/transparent"
instead of #00000000

Transparent LinearLayout on Android

I have the folowing layout:
I want to make transparent the transparent_layout but i can't do it.
Already tried settings the background programmatically with the color: Color.TRANSPARENT but it seems it doesnt work.
Im using Android 2.3.3 SDK with SherlockActionBar.
Is there any way to set that layout to transparent?
Depending upon the degree of opacity you like, set the background color like
android:background="#00ffffff"
The first two digits are for opacity level, (aka alpha) that varies from 00 to ff (fully-transparent to fully-opaque), the remaining digits are for the desired background color. If you keep first 2 digits zero (00), then whatever color you choose for the remaining digits, doesn't matter.
In XML change the main layout's (LinearLayout) background as android:background="#android:color/transparent" and also make sure that you are not giving the background to any of its child views.
Try this:
android:background="#android:color/transparent"

android.R.color.transparent not fully transparent

In my application, I apply the transparent background to my ListView's CustomListItem at runtime. For that I use, convertView.setBackgroundColor(android.R.color.transparent);. It works and shows transparency. But that is not fully transparent as there is some kind of shade to the background. I also tried putting my own transparent color with the values #80000000 and #00000000 but the result is worse. What can I do to get the fully transparent color?
Set this attribute to your listview in xml file
android:background="#android:color/transparent"
and also apply the transparent background to your ListView's CustomListItem at runtime.
For that you have use,
convertView.setBackgroundColor(Color.TRANSPARENT);
Thanks
android.R.color.transparent is a resource id (referring to a transparent color definition) - View.setBackgroundColor(int) expects an actual int color.
Use View.setBackgroundResource(int) instead, which will load the actual color from resources.
convertView.setBackgroundColor(Color.argb(0, 0, 0, 0));
OR
convertView.setBackgroundColor(Color.parseColor("#00000000"));
Use this from now in your xml's files when you want transparency in your views:
android:background="#null"
You are going to get a better performance.
Try:
convertView.setBackgroundColor(Color.argb(0, 0, 0, 0));

Categories

Resources