Android 进度条显示在标题栏的实现方法
程序员文章站
2024-02-21 16:31:22
好吧,先给大家展示效果图:
xml文件:
好吧,先给大家展示效果图:
xml文件:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" > <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" 显示"/> <button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="隐藏"/> </linearlayout>
java文件:
package com.imooc.progressbarr; import android.os.bundle; import android.app.activity; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.view.window; import android.widget.button; public class mainactivity extends activity { private button btn1; private button btn2; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //设置窗口特征:启用显示进度的进度条 requestwindowfeature(window.feature_progress); //设置窗口特征:启用不显示进度的进度条 requestwindowfeature(window.feature_indeterminate_progress); setcontentview(r.layout.activity_main); button btn1=(button)findviewbyid(r.id.button1); button btn2=(button)findviewbyid(r.id.button2); btn1.setonclicklistener(new onclicklistener(){ @override public void onclick(view v) { // todo auto-generated method stub //显示不带进度的进度条 setprogressbarindeterminatevisibility(true); //显示不带进度的进度条 setprogressbarvisibility(true); //设置进度条的进度 setprogress(4500); } }); btn2.setonclicklistener(new onclicklistener(){ @override public void onclick(view v) { // todo auto-generated method stub //隐藏不带进度的进度条 setprogressbarindeterminatevisibility(false); //隐藏带进度的进度条 setprogressbarvisibility(false); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate the menu; this adds items to the action bar if it is present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
以上所述是小编给大家介绍的android 进度条显示在标题栏的实现方法,希望对大家有所帮助
下一篇: PHP实现适用于自定义的验证码类
推荐阅读