i trying create progress bar can used across multiple activities in app. progress bar contains logic such when reset, speed of progress bar increments etc.
instead of creating , coding logic implement progress bar in each activity create in separate class unsure of how this. have come across include tag allows re-use layouts not sure how implement logic accompanies progress bar. have advice/suggestion best way approach this?
as wrote in comment can define custom activity methods showing / hiding progress bar , make other activities extending it.
i provide example custom progressdialog:
public class baseactivity extends appcompatactivity { private myprogressdialog mloader; protected void showloader() { if (mloader == null) { mloader = new myprogressdialog(this); } if (!mloader.isshowing()) { mloader.show(); } } protected void hideloader() { if (mloader != null && mloader.isshowing()) { mloader.dismiss(); } } } public class myactivity extends baseactivity { // here can use showloader , hideloader wherever need }
of course can use whatever want instead of standard progressdialog. example can define custom view. important regardless of how implement loader in baseactivity, modifications available activities.
here example of progress dialog simple custom layout.
public class myprogressdialog extends progressdialog { public myprogressdialog(context context) { super(context, r.style.apptheme_translucent); } public myprogressdialog(context context, int theme) { super(context, theme); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.dialog_progress); setcancelable(false); } @override public void setcancelable(boolean flag) { super.setcancelable(flag); } }
here dialog_progress.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:background="#80000000" android:keepscreenon="true" > <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:background="@drawable/bg_progress_dialog" > <progressbar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:layout_margin="12dp" android:indeterminatetint="#00acff" android:indeterminatetintmode="src_in" /> </relativelayout> </relativelayout>
here bg_progress_dialog.xml
:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@android:color/black" /> <corners android:radius="10dp" /> </shape>
here style put in styles.xml
:
<style name="apptheme.translucent"> <item name="android:windowistranslucent">true</item> <item name="android:windowbackground">@android:color/transparent</item> </style>
Comments
Post a Comment