好吧,先给大家展示效果图:
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 进度条显示在标题栏的实现方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!
新闻热点
疑难解答