I already have the
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_profile);
and the
setProgressBarIndeterminateVisibility(true);
if (isOnline()) {
retrieveProfile();
} else {
Toast.makeText(ProfileActivity.this, getString(R.string.internet_error), Toast.LENGTH_LONG).show();
}
setProgressBarIndeterminateVisibility(false);
This code was already working, but somehow the progress bar doesn't show anymore.
Any idea would be appreciated!
That function doesn't show the bar, it just makes it show an indeterminate bar rather than a determinate bar. You still need to call setProgressBarVisibility(true);
Try this...
setSupportProgressBarIndeterminateVisibility(boolean)
to get backward compatibility.
Related
I'm developing an android app in which I'm downloading some data from Firebase and showing it in my app.
I have set a ProgressBar which becomes visible on launch of the activity and becomes invisible when the data is fully loaded.
I have set up a Handler that after 5 secs if the progress bar is visible a Snackbar would be shown. The problem is that snackbar is getting shown even when the progress bar becomes invisible before 5 secs.
Here's what I have done:
Handler slowInternetConnection = new Handler();
slowInternetConnection.postDelayed(new Runnable() {
#Override
public void run() {
if (progressBarLoadingRequests.getVisibility() == View.VISIBLE) {
snackbar = Snackbar
.make(coordinatorLayout, "It seems there is some problem with the network. Please wait...", Snackbar.LENGTH_LONG);
snackbar.setDuration(Snackbar.LENGTH_INDEFINITE);
snackbar.show();
} else {
Toast.makeText(getBaseContext(), "not showed", Toast.LENGTH_SHORT).show();
}
}
}, 5000);
I would like to know that whether checking on this: progressBarLoadingRequests.getVisibility() == View.VISIBLE condition is appropriate to find out if progress bar is visible or invisible?
Or what else I can do to achieve what I want.
Please let me know.
That comparison should be valid. I have tested it on a sample I have with a progress bar and the statement works.
You could test it though by using a ProgressDialog which has a built in function isShowing(). It's simpler than using a ProgressBar because you do not need to to include it in your layout, but it will freeze the layout until the dialog is dismissed.
I have a progress bar that I want to click on and move the progress to the point clicked.
i have
pb = (ProgressBar) v.findViewById(R.id.progressBar);
pb.setOnClickListener(new ProgressBar.OnClickListener() {
public void onClick(View v) {
//
}
}
Basically I want it to behave like a SeekBar, but I need to use a progress bar because I am using a circular progress bar, and the code I have visually fits my needs.
cheers,
I went with a custom seekbar
https://github.com/JesusM/HoloCircleSeekBar/blob/master/lib/src/main/java/com/jesusm/holocircleseekbar/lib/HoloCircleSeekBar.java
This is a circular seekbar, as per my requirements
I have an activity that I want to show progress. I'm requesting the window feature before setContentView is called, yet I see no progress showing. Progress works on [0, 10000] according to the documentation. What am I missing?
The action bar appears like a normal action bar without progress, with a solid blue line underneath the title/menu
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_PROGRESS);
setProgressBarVisibility(true);
setProgress(5000);
super.onCreate(savedInstanceState);
// set content view
}
I am changing the colour of action bar using the following code.
actionBar= getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(backgroundColor));
This works perfectly fine in onCreate() method(i.e when my activity starts).
But when I am using the same code in Android 4.1 to change color of action bar in onClick() method(i.e when user clicks say a button) then it changes the color of action bar to 'white' ONLY whatsoever be the value of backgroundColor.
In Android 2.3 it works perfectly fine in both cases, whether called from onCreate or onClick().
It seems to be dead end for me.
It seems like for Android 4.0 up to Android 4.1 (4.2 is ok) you cannot change the action bar background once the activity has started.
So I guess a solution in those cases is to restart the activity with a different background color.
Not very elegant but thats the best I can come up with.
Something like this perhaps:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btn);
if (getIntent().hasExtra("color")) {
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(getIntent().getIntExtra("color", 0)));
}
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent it = getIntent();
it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
it.putExtra("color", Color.BLUE);
startActivity(it);
}
});
}
A workaround I used to solve this problem was to maintain a reference to the ColorDrawable that was used to set the background initially. Then, to change its colour, modify the colour of the Drawable, and then tell the activity to invalidate its options, which causes the ActionBar to be redrawn. Here's my code to set the action bar color:
ColorDrawable sBackgroundDrawable;
...
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void setActionBarColor(int color){
if(getSherlockActivity() != null && !mCallback.isNavDrawerShowing()){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN){
if(sBackgroundDrawable == null){
sBackgroundDrawable = new ColorDrawable(color);
getSherlockActivity().getSupportActionBar().setBackgroundDrawable(sBackgroundDrawable);
}else{
sBackgroundDrawable.setColor(color);
getSherlockActivity().invalidateOptionsMenu();
}
}else{
getSherlockActivity().getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
}
}
}
Based off of what steve_the_kid mentioned I was able to solve this by saving the color drawable.
ColorDrawable actionBarBackground = new ColorDrawable();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setBackgroundDrawable(actionBarBackground());
actionBarBackground.setColor(someColor);
}
void onSomethingClick() {
actionBarBackground.setColor(someOtherColor);
}
Sorry for such a late reply,But to help others I am replying to this question after so long.
Just set the Title of the action bar or make change in the icons or menu along with changing the colorDrawables.A simple change will recreate the action bar with new color.Even if you need same title or icon every time set same title or same icon.
I hope this will help others
I implemented Progress Bar on action bar during network call but displaying the progress Bar on Action Bar is too large. I want to set dynamic size of progressbar. I searched lot but not achieve my goal.so following is the code for ActionBar ProgressBar. Please anybody suggest me some answer and anybody having another way to do above task please tell me.
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); }
protected void onPreExecute() {
// Show IndeterminateProgressBar
setSupportProgressBarIndeterminateVisibility(true); }
protected void onPostExecute(Void result) {
setSupportProgressBarIndeterminateVisibility(false);}
Thanks In Advance
Set a Timer and use LayoutParams to change the size.
{ParentLayout}.LayoutParams params = new {ParentLayout}.LayoutParams(h,w);
progressBar.setLayoutParams(params);
And use the built-in java Timer to time it.