package com.home.test; import com.home.testwindowfeatureactivity.R; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.Window; import android.view.WindowManager; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setIndeterminateProgress(); // setCustomTitle(); // setLeftIcon(); // setNotTitle(); setProgress(); } /** * 标题栏设置为带进度条样式 */ private void setIndeterminateProgress() { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress); // 设置显示或隐藏 setProgressBarIndeterminateVisibility(true); } /** * 自己定义标题栏 */ private void setCustomTitle() { requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle); } /** * 设置标题栏左边图标 */ private void setLeftIcon() { requestWindowFeature(Window.FEATURE_LEFT_ICON); setContentView(R.layout.main); getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher); } /** * 设置为无标题 */ private void setNotTitle() { requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); // 全屏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } /** * 设置为带水平进度条风格 */ private void setProgress() { requestWindowFeature(Window.FEATURE_PROGRESS); setProgressBarVisibility(true); setContentView(R.layout.main); setTitle("測试标题栏"); getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); // 通过线程来改变ProgressBar的值 new Thread(new Runnable() { public void run() { for (int i = 0; i < 10; i++) { try { Thread.sleep(1000); Message m = new Message(); m.what = (i + 1) * 20; MainActivity.this.handler.sendMessage(m); } catch (Exception e) { e.printStackTrace(); } } } }).start(); } Handler handler = new Handler() { // @Override public void handleMessage(Message msg) { super.handleMessage(msg); // 设置标题栏中前景的一个进度条进度值 setProgress(100 * msg.what); // 设置标题栏中后面的一个进度条进度值 setSecondaryProgress(100 * msg.what + 10); } }; }