Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing translucent background color of progressbar android

I want to change background color of the progressbar having black translucent background with opacity less than 50%. I searched a lot about this but not able to find solution. I don't know whether i'm right or not but it has some thing to do with mdecor property of the progressbar.

Following is the code I am using it.

pd = ProgressDialog.show(getActivity(), null, null,true);       
pd.setContentView(R.layout.remove_border);

The code for remove border layout is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical" >

<ProgressBar
    android:id="@+id/progressBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@android:color/transparent"
    android:indeterminateDrawable="@drawable/my_progress_indeterminate" />

</LinearLayout>

The code for my_progress_indeterminate is:

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loadingiconblack"
android:pivotX="50%"
android:pivotY="50%" />

Following is the image the background area is marked in red circle. I want to change color to white with same opacity.

enter image description here

EDIT:

Final solution to my issue thanks to Sripathi and user3298272 combining both solutions here is my updated answer:

pd = new Dialog(this, android.R.style.Theme_Black);
View view = LayoutInflater.from(this).inflate(R.layout.remove_border, null);
pd.requestWindowFeature(Window.FEATURE_NO_TITLE);
pd.getWindow().setBackgroundDrawableResource(R.color.transparent);
pd.setContentView(view);
pd.show();

remove_border xml code: Here android:gravity = "center" is added in linear layout code of mine.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="vertical" >

<ProgressBar
    android:id="@+id/progressBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@android:color/transparent"
    android:indeterminateDrawable="@drawable/my_progress_indeterminate" />

</LinearLayout>

color xml code:

<resources>

  <color name="transparent">#80FFFFFF</color>

</resources>

In #80FFFFFF 80 is the opacity value 50% which i took from user3298272.

like image 670
Niranjan Balkrishna Prajapati Avatar asked May 26 '14 11:05

Niranjan Balkrishna Prajapati


2 Answers

Here is the transparent color ratio for the Hex color codes.
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
Just add the percentage of opacity before the color code. For example : color code for black is #0000. If i want transparent black with 50% transparency means just add 80 before #0000(i.e. #800000)

like image 107
Chandru Avatar answered Sep 21 '22 22:09

Chandru


You can use dialog instead of progressdialog,

    dialogTransparent = new Dialog(this, android.R.style.Theme_Black);
    View view = LayoutInflater.from(getActivity()).inflate(
            R.layout.remove_border, null);
    dialogTransparent.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialogTransparent.getWindow().setBackgroundDrawableResource(
            R.color.transparent);
    dialogTransparent.setContentView(view);

Update:

   Here the color transparent is  #80FFFFFF
like image 41
Sripathi Avatar answered Sep 20 '22 22:09

Sripathi