xml文件代碼部分
<ProgressBar android:id="@+id/firstprobar" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="200" android:progress="100" /> <Button android:id="@+id/bt1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/firstprobar" android:text="前進" /> <Button android:id="@+id/bt2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/bt1" android:text="后退" />
Mainactivity中代碼
private ProgressBar probar;
private Button bt1;
private Button bt2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
probar=(ProgressBar)findViewById(R.id.firstprobar);
probar.setMax(100);
/*probar.setProgress(20);
boolean flag=probar.isIndeterminate();
Toast.makeText(getApplicationContext(), flag+"", Toast.LENGTH_LONG).show();*/
bt1=(Button)findViewById(R.id.bt1);
bt2=(Button)findViewById(R.id.bt2);
FirstLis f=new FirstLis();
SecondLis s=new SecondLis();
bt1.setOnClickListener(f);
bt2.setOnClickListener(s);
}
class FirstLis implements OnClickListener{
@Override
public void onClick(View v) {
probar.incrementProgressBy(10);
}
}
class SecondLis implements OnClickListener{
@Override
public void onClick(View v) {
probar.incrementProgressBy(-10);
}
}免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。