Android ProgressBar UI custom layout
The solution (feels weird answering your own):
First, one problem was that progress drawable had a different size than background (stupid me!). Also, for progress drawable a clip xml was needed. Something like progressbar_progress_clip.xml:
<?xml version="1.0" encoding="utf-8"?>
<clip
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progressbar_progressing"
android:clipOrientation="horizontal"
android:gravity="left"/>
Then, add the progress bar and two images in a relative layout, so that the images can be drawn after the status bar. Something like this:
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_weight="94" >
<ProgressBar
android:id="@+id/pBarOverallStatus"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:indeterminateOnly="false"
android:max="100"
android:progressDrawable="@drawable/progressbar_progress_clip" >
</ProgressBar>
<ImageView
android:id="@+id/ringLeft"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="7dp"
android:contentDescription="@string/status_bar_ring"
android:src="@drawable/status_bar_ring" />
<ImageView
android:id="@+id/ringRight"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="7dp"
android:contentDescription="@string/status_bar_ring"
android:src="@drawable/status_bar_ring" />
</RelativeLayout>
Thanks, guys!
How to Customize a Progress Bar In Android
Customizing a ProgressBar
requires defining the attribute or properties for the background and progress of your progress bar.
Create an XML file named customprogressbar.xml
in your res->drawable
folder:
custom_progressbar.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="@android:id/background">
<shape>
<gradient
android:startColor="#000001"
android:centerColor="#0b131e"
android:centerY="1.0"
android:endColor="#0d1522"
android:angle="270"
/>
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="@android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#007A00"
android:centerColor="#007A00"
android:centerY="1.0"
android:endColor="#06101d"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
Now you need to set the progressDrawable
property in customprogressbar.xml
(drawable)
You can do this in the XML file or in the Activity (at run time).
Do the following in your XML:
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="@drawable/custom_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
At run time do the following
// Get the Drawable custom_progressbar
Drawable draw=res.getDrawable(R.drawable.custom_progressbar);
// set the drawable as progress drawable
progressBar.setProgressDrawable(draw);
Edit: corrected xml layout
How can I add a custom progress bar before logging in?
First of all, thats not how asynchronous calls are made, if timeout occurs, your code may show a progressbar and stops executing unless button is pressed again,
You should implement a thread and use an interface for callbacks, dismiss the dialog on connection or login completed event.Also you will not need to wait for x seconds if you are in background thread waiting for callbacks, (5 milliseconds is a very short time for a network call, even your ping might take upto 100ms)
And remember to keep reference to the dialog so you can latter dismiss it, i don't think your are doing that even in the code not shared in the question
How to communicate with ui thread
Easier example
In your class, outside oncreate
AlertDialog builder; //you can name it anything
In your progressDialog
builder = new AlertDialog.Builder(this)
instead of
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
And on connection or login event (or whenever you want to dismiss the dialog
if (builder!=null) {
builder.dismiss();
builder = null; //newbies safety
}
Custom Title Bar with Progress in Android
I believe the only way to do it is to use your own custom title bar. You COULD override the android code since its open source -- but that might be a bad idea. The best thing to do is to make a title bar layout and just <include />
it in all the other layouts and maybe have a helper class to show and hide the progress bar.
Android- How to use another layout as progressbar
There are many ways you can achieve this. I saw you one way.
You can make a Custom Dialog
and load this layout using Inflater
and set layout to your Dialog
. like
LayoutInflater factory = LayoutInflater.from(Activity.this);
View DialogView = factory.inflate(R.layout.custom_progress_layout, null);
Dialog main_dialog = new Dialog(Activity.this,R.style.Theme_Dialog);
main_dialog.setContentView(DialogView);
progressBar=(ProgressBar)DialogView.findViewById(R.id.progressBar1);
main_dialog.setCancelable(false);
main_dialog.setCanceledOnTouchOutside(false);
progressBar.setProgress(0);
progressBar.setMax(100);
main_dialog.show();
and when your progress is completed you dismiss
this dialog using main_dialog.dismiss();
also in this layout you can display progress text and progress by using some TextView
.
Output:
How to customize border width of ProgressBar
Create a file with shape drawable for your progress
<?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">
<solid
android:color="#F3A523"/>
</shape>
</rotate>Use it inside your
ProgressBar
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="24dp"
android:layout_height="24dp"
android:indeterminate="true"
android:progressDrawable="@drawable/progress_bar"
android:indeterminateDrawable="@drawable/progress_bar"
/>
This way you can control width of your border via thicknessRatio
property of the drawable
Related Topics
How to Get Add to Home Screen Pop Up on Site Open in Mobile Browser
Calculate the Size of a List View or How to Tell It to Fully Expand
How to Use Google Login API with Cordova/Phonegap
How to Capture an Image in Background Without Using the Camera Application
How to Add Button in Actionbar(Android)
Edittext in Listview Loses Focus When Pressed on Android 4.X
Running a Specific Instrumentation Unit Test with Gradle
Play Sound on Phonegap App for Android
Phonegap - Navigator.App.Backhistory() Not Working on HTML Back Button
Google Maps API Version Difference
How to Combine Bottomappbar + Fab with Bottomnavigationview
Android - Communicating Between Two Devices
How to Open Private Files Saved to the Internal Storage Using Intent.Action_View
How to Have a Gridview That Adapts Its Height When Items Are Added
Android- How to Convert Android.Net.Uri Object to Java.Net.Uri Object
Firebaseinitprovider: Firebaseapp Initialization Unsuccessful