How to create this type of progress bar in android without image? I need to show the gradient effect also. http://goldesel.to/img/loading.gif
Progress Dialog showing a progress indicator and an optional text message or view. Only a text message or a view can be used at the same time.
Create asyncTask class: ShowCustomProgressBarAsyncTask
public class ShowCustomProgressBarAsyncTask extends AsyncTask < Void,Integer,Void > {
int myProgress;
#Override
protected void onPostExecute(Void result) {
textview.setText("Finish work with custom ProgressBar");
button1.setEnabled(true);
progressBar2.setVisibility(View.INVISIBLE);
}
#Override
protected void onPreExecute() {
button1.setEnabled(false);
textview.setText("Start work with custom ProgressBar");
myProgress = 0;
progressBar.setSecondaryProgress(0);
}
#Override
protected Void doInBackground(Void...params) {
while (myProgress < 100) {
myProgress++;
publishProgress(myProgress);
SystemClock.sleep(100);
}
return null;
}#Override
protected void onProgressUpdate(Integer...values) {
progressBar.setProgress(values[0]);
progressBar.setSecondaryProgress(values[0] + 5);
}
}
And in file res/drawable/custom_progress_bar_horizontal.xml
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#ffdddddd"
android:centerY="0.50"
android:endColor="#ffffffff"
android:startColor="#ffffffff" />
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="90"
android:endColor="#771997e1"
android:startColor="#770e75af" />
</shape>
</clip>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="90"
android:endColor="#ff1997e1"
android:startColor="#ff0e75af" />
</shape>
</clip>
</item>
</layer-list>
OUTPUT:
For more Information refer this
Related
I am not able to show the shadow of the indicator above the indicatior height within the tabs. i am using the karim library for material tabs,where i apply elevation but that does not help.How can i accheive shadow within the tab?
layout
<io.karim.MaterialTabs
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentBottom="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#android:color/transparent"
android:textColor="#color/white"
app:mtIndicatorColor="#color/colorPrimaryRed"
app:mtIndicatorHeight="3dp"
app:mtPaddingMiddle="false"
app:mtSameWeightTabs="true"
app:mtTabPaddingLeftRight="10dp" />
test drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:left="-11dp" android:right="-11dp" android:top="-11dp">
<shape>
<stroke android:width="10dp" android:color="#color/colorPrimaryRed" />
<gradient android:angle="90" android:endColor="#00fafafa" android:startColor="#88d66f67" android:type="linear" />
<corners android:radius="2dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
java
class StarterMenuAdapter extends FragmentPagerAdapter {
public StarterMenuAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
if (position == 1) {
LoginFragment loginFragment = new LoginFragment();
return loginFragment;
} else {
RegisterFragment registerFragment = new RegisterFragment();
return registerFragment;
}
}
#Override
public CharSequence getPageTitle(int position) {
return CONTENT[position % CONTENT.length].toUpperCase();
}
#Override
public int getCount() {
return CONTENT.length;
}
}
want to achieve
what i got
how can shadow within the tab be achieved?
It is similar as you want,
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:left="-8dp" android:right="-8dp" android:top="-8dp">
<shape>
<stroke android:width="7dp" android:color="#color/red" />
<gradient android:angle="90" android:endColor="#00fafafa" android:startColor="#88d66f67" android:type="linear" />
<corners android:radius="2dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
Output
I want to change the seek bar color in android when the progress changes. In the following picture, blue color from 1-2, green from 2-3 and so on. Is it possible?
So far, my code is;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SeekBar seekBar = (SeekBar)findViewById(R.id.seekbar);
seekBar.setProgress(0);
seekBar.incrementProgressBy(10);
seekBar.setMax(200);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = progress / 10;
progress = progress * 10;
int stepSize = 25;
progress = (progress/stepSize)*stepSize;
seekBar.setProgress(progress);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
progress.xml
----------
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background"
android:drawable="#drawable/background_fill" />
<item android:id="#android:id/progress">
<clip android:drawable="#drawable/progress_fill" />
</item>
</layer-list>
background_fill.xml
----------
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FF555555"
android:centerColor="#FF555555"
android:endColor="#FF555555"
android:angle="90" />
<corners android:radius="5px" />
<stroke
android:width="2dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
----------
progress_fill.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FF470000"
android:centerColor="#FFB80000"
android:endColor="#FFFF4400"
android:angle="180" />
<corners android:radius="5px" />
<stroke
android:width="2dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
----------
In xml where You write seekabr code add this
android:thumb="#drawable/thumb"
I hope this code is help to solve Your Problem.
Do You have idea How can you add These Files in Your Project
I have a question, I have a seek bar and I want to show the buffer progress of an ExoPlayer media file using the secondary progress bar of the seekBar, the problem is that it´s not showing. Im running on API 21
Here´s the xml code:
<SeekBar
android:id="#+id/seekBarAudioA"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:maxHeight="3dip"
android:minHeight="3dip"
android:progressDrawable="#drawable/seek_bar_progress"
android:secondaryProgressTint="#android:color/holo_blue_dark"
android:thumbTint="#color/amber"
app:layout_constraintBottom_toBottomOf="#+id/play_pause"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="#+id/play_pause"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/play_pause" />
and here´s the java code:
SeekBar = new Thread(new Runnable() {
#Override
public void run() {
try {
while (currentlyPlaying && currentAudioHolder.getAdapterPosition() == audioPosition) {
int duration = (int) exoPlayer.getDuration();
currentAudioHolder.seekBarAudio.setMax(duration);
currentAudioHolder.seekBarAudio.setSecondaryProgress((int) exoPlayer.getBufferedPosition());
final int currPosition = (int) exoPlayer.getCurrentPosition();
Log.d("Buffer", "secondary progress bar position is: " + (int) exoPlayer.getBufferedPosition() + ", and the current position is: " + currPosition);
currentAudioHolder.seekBarAudio.setProgress(currPosition);
((ChatActivity) context).runOnUiThread(new Runnable() {
#Override
public void run() {
currentAudioHolder.audioLength.setText(convertTime(currPosition));
}
});
Thread.sleep(sleep);
}
} catch (InterruptedException i) {
currentlyPlaying = false;
}
}
});
SeekBar.start();
Please help :(
I might be late, but here is my answer: you should check your seek_bar_progress file, that you use for android:progressDrawable, and see if it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background">
<shape android:shape="rectangle">
<corners android:radius="2dp"/>
<solid android:color="#color/myBgColor"/>
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<scale android:scaleWidth="100%">
<shape android:shape="rectangle">
<corners android:radius="2dp"/>
<solid android:color="#color/myColor"/>
</shape>
</scale>
</item> <item android:id="#android:id/progress">
<clip>
<shape android:shape="rectangle">
<corners android:radius="2dp"/>
<solid android:color="#color/myColor"/>
</shape>
</clip>
</item>
</layer-list>
I found out that the part with the #android:id/secondaryProgress id was missing in my drawable, and that was the reason why it was not working for me.
Hope it helps.
I have a strange behavior on my custom ProgressBar. On Android <4.4, I get a good result. But on Android 4.4, I get artifacts while the ProgressBar is decreasing:
The colors are defined here:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/background">
<clip>
<shape>
<corners android:radius="0dip" />
<gradient
android:angle="90"
android:centerColor="#004676"
android:centerY="0.75"
android:startColor="#004676" />
</shape>
</clip>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="0dip" />
<gradient
android:angle="90"
android:endColor="#ee7407"
android:startColor="#ee7407" />
</shape>
</clip>
</item>
And in my custom ProgressBar class, I define it as follows:
private void init() {
this.setMax(MAX);
this.setProgress(MAX);
_timer = new CountDownTimer(TIME * 1000, 100) {
public void onTick(long millisUntilFinished) {
decreaseProgress();
}
public void onFinish() {
finished();
}
};
}
private void decreaseProgress() {
this.setProgress(this.getProgress() - 1);
}
Does anybody have a hint for me? Thanks in advance!
I've encountered exactly the same problem on Nexus 5.
Currently I have no time to dig into source codes and find the difference, but I found it possible to suppress this issue if you invalidate your progress bar everytime right after setting progress to it.
In your situation, it should be:
private void decreaseProgress() {
this.setProgress(this.getProgress() - 1);
this.postInvalidate();
}
Hope this could help!
I want to apply effect to seekbar as shown below:
Download it...
What I have tried is as below.The complete code is below just try and let me know if you will get the effect like below.
MainActivity.java
public class MainActivity extends Activity
{
private static int myProgress=0;
private SeekBar seekBar;
private int progressStatus=0;
private Handler myHandler=new Handler();
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.h_processbar);
}
public void beginYourTask(View view)
{
myProgress=0;
seekBar= (SeekBar)findViewById(R.id.seekBar);
seekBar.setMax(100);
new Thread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
while(progressStatus<100)
{
progressStatus=performTask();
myHandler.post(new Runnable()
{
public void run() {
seekBar.setProgress(progressStatus);
}
});
}
myHandler.post(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(),"Task Completed",Toast.LENGTH_LONG).show();
progressStatus=0;
myProgress=0;
}
});
}
private int performTask()
{
try {
//---Do some task---
Thread.sleep(100);
} catch (InterruptedException e)
{
e.printStackTrace();
}
return ++myProgress;
}
}).start();
}
}
progress_horizontal_green.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ff54e854"
android:centerColor="#ff004900"
android:endColor="#ff54e854"
android:angle="90"
/>
</shape>
</clip>
</item>
</layer-list>
h_processbar.xml
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="beginYourTask"
android:text="Start Task"
android:textColor="#ffffff"
android:layout_margin="10dp"/>
<LinearLayout
android:layout_width="290dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
>
<SeekBar
android:id="#+id/seekBar"
android:max="100"
android:progress="60"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:thumb="#drawable/down_arrow_new"
android:progressDrawable="#drawable/progress_horizontal_green"
android:layout_margin="20dp"
/>
</LinearLayout>
down_arrow_new.png is here Download it...
As shown in figure LHS(left hand side) it starts from dark green color and as progress goes forward it looks like the combination of light green shades with blur effect.
and blur effect makes this awesome.
How can i achieve this?Any idea?
Any help will be appreciated.
Thank you.