Android开源:CProgressButton -仿 iOS 的下载按钮
biaoaction
8年前
<h2>CProgressButton</h2> <p>a circle progress button like iOS</p> <p style="text-align:center"><img src="https://simg.open-open.com/show/b1dd11e4dcd60ce47dff1d4228fd3d9a.gif"></p> <h2>Usage:</h2> <h3>code</h3> <pre> <code class="language-java">final CProgressButton progressButton = (CProgressButton)findViewById(R.id.btn); progressButton.setbgDrawable(R.drawable.bounder,40); //config bg progressButton.setStroke(1,R.color.colorAccent); //config stroke color final TextView tv = (TextView) findViewById(R.id.state); progressButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ValueAnimator valueAnimator = ValueAnimator.ofInt(0,100); if(progressButton.getState() == CProgressButton.STATE.NORMAL){ progressButton.setState(CProgressButton.STATE.PROGRESS); valueAnimator.setDuration(5000); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int value = (int)animation.getAnimatedValue(); tv.setText("state progress:"+value); if(value == 100){ progressButton.setState(CProgressButton.STATE.NORMAL); tv.setText("state normal"); progressButton.setText("Finish"); } progressButton.setProgress(value); } }); valueAnimator.start(); }else{ valueAnimator.cancel(); progressButton.setState(CProgressButton.STATE.NORMAL); tv.setText("state normal"); progressButton.setText("Continue"); } } });</code></pre> <h3>layout</h3> <pre> <code class="language-java"><com.jiang.android.cprogressbutton.CProgressButton android:layout_width="65dp" android:layout_marginLeft="50dp" android:text="Download" android:gravity="center" android:textSize="12sp" android:textColor="@color/colorAccent" android:id="@+id/btn" android:layout_height="30dp" /></code></pre> <h3>License</h3> <pre> <code class="language-java">Copyright 2016 NewTab Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.</code></pre> <p> </p> <p> </p> <p> </p>