当前位置:操作系统 > 安卓/Android >>

Android ApiDemos示例解析(185):Views->Progress Bar->4. In Title Bar

介绍过Activity本身提供了可以控制显示在Titlebar的进度条显示 ,那个例子使用是水平进度条,本例在Titlebar中显示一个Spinning wheel 。

首先需要设置在 Titlebar 的进度条的可用性,setProgressBarIndeterminateVisibility 设置 “Indeterminate” 模式的进度条的可见性,而setProgressBarVisibility 设置水平进度条的可见性。

在Titlebar中的进度条无需在Layout中描述。R.layout.progressbar_4.xml 定义如下:


[html]
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” 
android:orientation=”vertical” 
android:layout_width=”match_parent” 
android:layout_height=”wrap_content”> 
 
<Button android:id=”@+id/toggle” 
android:layout_width=”wrap_content” 
android:layout_height=”wrap_content” 
android:text=”@string/progressbar_4_toggle” /> 
 
</LinearLayout> 

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”>

<Button android:id=”@+id/toggle”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/progressbar_4_toggle” />

</LinearLayout>
本例使用一个按钮来切换标题栏中进度滚轮的可见性:

 

[java]
Button button = (Button) findViewById(R.id.toggle); 
button.setOnClickListener(new Button.OnClickListener() { 
 public void onClick(View v) { 
 mToggleIndeterminate = !mToggleIndeterminate; 
 setProgressBarIndeterminateVisibility 
 (mToggleIndeterminate); 
 } 
}); 

Button button = (Button) findViewById(R.id.toggle);
button.setOnClickListener(new Button.OnClickListener() {
 public void onClick(View v) {
 mToggleIndeterminate = !mToggleIndeterminate;
 setProgressBarIndeterminateVisibility
 (mToggleIndeterminate);
 }
});

 

\

 

 

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,