码迷,mamicode.com
首页 > Windows程序 > 详细

requestWindowFeature使用详解

时间:2014-12-16 19:02:12      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   ar   io   os   使用   sp   

requestWindowFeature使用详解 - - ITeye技术网站

requestWindowFeature可以设置的值有:
 // 1.DEFAULT_FEATURES:系统默认状态,一般不需要指定
        // 2.FEATURE_CONTEXT_MENU:启用ContextMenu,默认该项已启用,一般无需指定
        // 3.FEATURE_CUSTOM_TITLE:自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时
        // 4.FEATURE_INDETERMINATE_PROGRESS:不确定的进度
        // 5.FEATURE_LEFT_ICON:标题栏左侧的图标
        // 6.FEATURE_NO_TITLE:无标题
        // 7.FEATURE_OPTIONS_PANEL:启用“选项面板”功能,默认已启用。
        // 8.FEATURE_PROGRESS:进度指示器功能
        // 9.FEATURE_RIGHT_ICON:标题栏右侧的图标

效果图:
 default:
bubuko.com,布布扣
 
 progress:


bubuko.com,布布扣

no title:


bubuko.com,布布扣
 
 lefticon:


bubuko.com,布布扣
 fullscreen:
bubuko.com,布布扣
 indeterminate_progress:
bubuko.com,布布扣
 

customtitle:


bubuko.com,布布扣
 

 

代码:

Java代码  bubuko.com,布布扣
  1. package com.my;  
  2. import android.app.Activity;  
  3. import android.os.Bundle;  
  4. import android.os.Handler;  
  5. import android.os.Message;  
  6. import android.view.Window;  
  7. import android.view.WindowManager;  
  8. public class WindowFeatureDemoActivity extends Activity {  
  9.     @Override  
  10.     public void onCreate(Bundle savedInstanceState) {  
  11.         super.onCreate(savedInstanceState);  
  12.         // requestWindowFeature();的取值  
  13.         // 1.DEFAULT_FEATURES:系统默认状态,一般不需要指定  
  14.         // 2.FEATURE_CONTEXT_MENU:启用ContextMenu,默认该项已启用,一般无需指定  
  15.         // 3.FEATURE_CUSTOM_TITLE:自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时  
  16.         // 4.FEATURE_INDETERMINATE_PROGRESS:不确定的进度  
  17.         // 5.FEATURE_LEFT_ICON:标题栏左侧的图标  
  18.         // 6.FEATURE_NO_TITLE:无标题  
  19.         // 7.FEATURE_OPTIONS_PANEL:启用“选项面板”功能,默认已启用。  
  20.         // 8.FEATURE_PROGRESS:进度指示器功能  
  21.         // 9.FEATURE_RIGHT_ICON:标题栏右侧的图标  
  22.         // ========================FEATURE_INDETERMINATE_PROGRESS:不确定的进度  
  23. //        showFEATURE_INDETERMINATE_PROGRESS();  
  24. //        // =====================FEATURE_CUSTOM_TITLE         
  25. //        showFEATURE_CUSTOM_TITLE();  
  26. //        // ======================== FEATURE_LEFT_ICON:标题栏左侧的图标  
  27. //        showFEATURE_LEFT_ICON();  
  28. //        // ======================FEATURE_NO_TITLE  
  29. //        showFEATURE_NO_TITLE();     
  30. //         =================================FEATURE_PROGRESS  
  31.         showFEATURE_PROGRESS();  
  32.     }  
  33.     private void showFEATURE_INDETERMINATE_PROGRESS() {  
  34.         requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
  35.         setContentView(R.layout.main);  
  36.         getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);  
  37.         // 必须得加上否则显示不出效果 可以通过这个在以后设置显示或隐藏  
  38.         setProgressBarIndeterminateVisibility(true);  
  39.     }  
  40.     private void showFEATURE_CUSTOM_TITLE() {  
  41.         // 自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时  
  42.         requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
  43.         setContentView(R.layout.main);  
  44.         getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);  
  45.     }  
  46.     private void showFEATURE_LEFT_ICON()  
  47.     {  
  48.          requestWindowFeature(Window.FEATURE_LEFT_ICON);  
  49.          setContentView(R.layout.main);  
  50.          getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,  
  51.          R.drawable.icon);  
  52.     }  
  53.     private void showFEATURE_NO_TITLE()  
  54.     {  
  55.          requestWindowFeature(Window.FEATURE_NO_TITLE);  
  56.          setContentView(R.layout.main);  
  57.          // 加上这句设置为全屏 不加则只隐藏title  
  58.          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
  59.          WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  60.     }  
  61.     private void showFEATURE_PROGRESS()  
  62.     {  
  63.         requestWindowFeature(Window.FEATURE_PROGRESS);  
  64.         setProgressBarVisibility(true);  
  65.         setContentView(R.layout.main);  
  66.         setTitle("");  
  67.         getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);  
  68.         // 通过线程来改变ProgressBar的值  
  69.         new Thread(new Runnable() {  
  70.             public void run() {  
  71.                 for (int i = 0; i < 10; i++) {  
  72.                     try {  
  73.                         Thread.sleep(1000);  
  74.                         Message m = new Message();  
  75.                         m.what = (i + 1) * 20;  
  76.                         WindowFeatureDemoActivity.this.myMessageHandler.sendMessage(m);  
  77.                     } catch (Exception e) {  
  78.                         e.printStackTrace();  
  79.                     }  
  80.                 }  
  81.             }  
  82.         }).start();  
  83.     }  
  84.     Handler myMessageHandler = new Handler() {  
  85.         // @Override  
  86.         public void handleMessage(Message msg) {  
  87.             // 设置标题栏中前景的一个进度条进度值  
  88.             setProgress(100 * msg.what);  
  89.             // 设置标题栏中后面的一个进度条进度值  
  90.             setSecondaryProgress(100 * msg.what + 10);  
  91.             super.handleMessage(msg);  
  92.         }  
  93.     };  
  94. }  
package com.my;
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 WindowFeatureDemoActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // requestWindowFeature();的取值
        // 1.DEFAULT_FEATURES:系统默认状态,一般不需要指定
        // 2.FEATURE_CONTEXT_MENU:启用ContextMenu,默认该项已启用,一般无需指定
        // 3.FEATURE_CUSTOM_TITLE:自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时
        // 4.FEATURE_INDETERMINATE_PROGRESS:不确定的进度
        // 5.FEATURE_LEFT_ICON:标题栏左侧的图标
        // 6.FEATURE_NO_TITLE:无标题
        // 7.FEATURE_OPTIONS_PANEL:启用“选项面板”功能,默认已启用。
        // 8.FEATURE_PROGRESS:进度指示器功能
        // 9.FEATURE_RIGHT_ICON:标题栏右侧的图标
        // ========================FEATURE_INDETERMINATE_PROGRESS:不确定的进度
//        showFEATURE_INDETERMINATE_PROGRESS();
//        // =====================FEATURE_CUSTOM_TITLE
//        showFEATURE_CUSTOM_TITLE();
//        // ======================== FEATURE_LEFT_ICON:标题栏左侧的图标
//        showFEATURE_LEFT_ICON();
//        // ======================FEATURE_NO_TITLE
//        showFEATURE_NO_TITLE();
//         =================================FEATURE_PROGRESS
        showFEATURE_PROGRESS();
    }
    private void showFEATURE_INDETERMINATE_PROGRESS() {
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);
        // 必须得加上否则显示不出效果 可以通过这个在以后设置显示或隐藏
        setProgressBarIndeterminateVisibility(true);
    }
    private void showFEATURE_CUSTOM_TITLE() {
        // 自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);
    }
    private void showFEATURE_LEFT_ICON()
    {
         requestWindowFeature(Window.FEATURE_LEFT_ICON);
         setContentView(R.layout.main);
         getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
         R.drawable.icon);
    }
    private void showFEATURE_NO_TITLE()
    {
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         setContentView(R.layout.main);
         // 加上这句设置为全屏 不加则只隐藏title
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
         WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    private void showFEATURE_PROGRESS()
    {
        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;
                        WindowFeatureDemoActivity.this.myMessageHandler.sendMessage(m);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }
    Handler myMessageHandler = new Handler() {
        // @Override
        public void handleMessage(Message msg) {
            // 设置标题栏中前景的一个进度条进度值
            setProgress(100 * msg.what);
            // 设置标题栏中后面的一个进度条进度值
            setSecondaryProgress(100 * msg.what + 10);
            super.handleMessage(msg);
        }
    };
}

 

requestWindowFeature使用详解

标签:android   style   blog   http   ar   io   os   使用   sp   

原文地址:http://www.cnblogs.com/seven1979/p/4167517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!