MainActivity.java
package com.test.myapplication; import android.app.ProgressDialog; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { private Button button; private ProgressDialog dialog; @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button)findViewById(R.id.btn); button.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { dialog = new ProgressDialog(MainActivity.this); dialog.getWindow().setBackgroundDrawable(new
ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.setIndeterminate(true); dialog.setCancelable(true); dialog.show(); dialog.setContentView(R.layout.my_progress); } }); } }
In res/layout
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="16dp" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" tools:context="com.test.myapplication.MainActivity"> <Button android:id="@+id/btn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Click" android:textSize="20sp" /> </RelativeLayout>
In res/layout
my_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminateDrawable="@drawable/myprogress_style" />
</RelativeLayout>
In res/drawable
myprogress_style.xml
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360"> <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="8" android:useLevel="false"> <gradient android:centerColor="#FFCC35" android:centerY="0.50" android:endColor="#CE0000" android:startColor="#CE0000" android:type="sweep" android:useLevel="false" /> </shape> </rotate>
Now Run the application.Try It...