Saturday, 28 October 2017

Custom Dialog Progressbar

step:1:

style.xml

<style name="Dialog" parent="android:Theme.Holo.Dialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textSize">12sp</item>
</style>
<style name="CustomAlertDialogStyle">
    <item name="android:bottomBright">@android:color/transparent</item>
    <item name="android:bottomDark">@android:color/transparent</item>
    <item name="android:bottomMedium">@android:color/transparent</item>
    <item name="android:centerBright">@android:color/transparent</item>
    <item name="android:centerDark">@android:color/transparent</item>
    <item name="android:centerMedium">@android:color/transparent</item>
    <item name="android:fullBright">@android:color/transparent</item>
    <item name="android:fullDark">@android:color/transparent</item>
    <item name="android:topBright">@android:color/transparent</item>
    <item name="android:topDark">@android:color/transparent</item>
</style>

step 2:

MainActivity.java

public class MainActivity extends AppCompatActivity {
 private static int SPLASH_TIME_OUT = 3000;
 ProgressDialog progressDialog;
@Override
 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        progressDialog=new ProgressDialog(ProfileActivity.this,R.style.Dialog);
        progressDialog.show();
 new Handler().postDelayed(new Runnable() {
  @Override
 public void run() {
     progressDialog.dismiss(); }
        }, SPLASH_TIME_OUT);
}}
///////////////////////////////////////////////////////////////

 methed 2:
step 1:
drawable/circular_progress_dialog.xml
<rotate xmlns:android="http://schemas.android.com/apk/res/android"    
android:fromDegrees="270"    
android:toDegrees="270">
    <shape        
android:innerRadiusRatio="2.5"        
android:shape="ring"        
android:thickness="5dp"        
android:useLevel="true">
<!-- this line fixes the issue for lollipop api 21 -->
        <gradient            
android:angle="0"            
android:endColor="#73052a"            
android:startColor="#d7bbc5"            
android:type="sweep"            
android:useLevel="false" />
    </shape>
</rotate>
step 2:

layout/dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
 xmlns:app="http://schemas.android.com/apk/res-auto"    
android:orientation="vertical" 
android:layout_width="match_parent"    
android:layout_height="match_parent"    
android:gravity="center">

    <ProgressBar       
 android:layout_width="wrap_content"       
 android:layout_height="wrap_content"        
android:indeterminateDrawable="@drawable/circular_progress_dialog"        />
</LinearLayout>
step 4:
res/style

<style name="Dialog" parent="android:Theme.Holo.Dialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textSize">12sp</item>
</style>
<style name="CustomAlertDialogStyle">
    <item name="android:bottomBright">@android:color/transparent</item>
    <item name="android:bottomDark">@android:color/transparent</item>
    <item name="android:bottomMedium">@android:color/transparent</item>
    <item name="android:centerBright">@android:color/transparent</item>
    <item name="android:centerDark">@android:color/transparent</item>
    <item name="android:centerMedium">@android:color/transparent</item>
    <item name="android:fullBright">@android:color/transparent</item>
    <item name="android:fullDark">@android:color/transparent</item>
    <item name="android:topBright">@android:color/transparent</item>
    <item name="android:topDark">@android:color/transparent</item>
</style>


step 5:

import android.app.Dialog;
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Dialog dialog = new Dialog(MainActivity.this,R.style.Dialog);
        dialog.setContentView(R.layout.dialog);
        dialog.show();
    }}

No comments:

Post a Comment

HOW TO CREATE CIRCLE IMAGE VIEW

Step 1: implementation 'de.hdodenhof:circleimageview:3.0.0' Step 2: <de.hdodenhof.circleimageview.CircleImageView xmlns:ap...