Android 进度条显示在标题栏的实现方法
时间:2021-02-17 14:02:36|栏目:Android代码|点击: 次
好吧,先给大家展示效果图:
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代码
本文地址:http://www.codeinn.net/misctech/64528.html