Reputation: 629
Edit: I realized that the code posted below works flawlessly in Nexus 6 (shamu) and Galaxy Tab A, both with android 7.0! And it does not show on Moto G5 Plus (android 7.0).
It's a simple question. My ProgressBar won't show up. At frist I was trying directly at my LoginActivity, but I wasn't having success. Things that i tried:
activity_test.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="context_name_here">
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
test.java:
package package_name_here;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class test extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
}
What's the problem? I suspect that is something about the resources... the image of the default progressbar or version of android... any ideas? Thanks
Upvotes: 0
Views: 7087
Reputation: 629
I figured out what was the problem. The Animator duration scale have to be ON at Developer options from device: Developer options -> Developer duration scale -> 1x (ON)
Upvotes: 9
Reputation: 396
Try with hard-coded dimension for the width and height for ProgressBar, also check your Colors that might be the same as activity default, also check by removing the style attribute once, or try with a different style for ProgressBar.
Upvotes: 1
Reputation: 13129
First you need to declare the progress dialog
private ProgressBar progressBar;
then in your onCreate
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar= new ProgressBar(test.this);
progressBar.show();
to dismiss the dialog or cancel it you can use
progressBar.cancel();
or progressBar.dismiss();
Upvotes: 0
Reputation:
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private int progressStatus = 0;
private TextView textView;
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
textView = (TextView) findViewById(R.id.textView);
// Start long running operation in a background thread
new Thread(new Runnable() {
public void run() {
while (progressStatus < 100) {
progressStatus += 1;
// Update the progress bar and display the
//current value in the text view
handler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
}
});
try {
// Sleep for 200 milliseconds.
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}
Define XML:
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginTop="20dp"
android:indeterminate="false"
android:max="100"
android:minHeight="50dp"
android:minWidth="200dp"
android:progress="1" />
<ProgressBar
android:id="@+id/progressBar_cyclic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:minWidth="50dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
Upvotes: 0