原链接:http://blog.csdn.net/yaoyeyzq/article/details/6393445
最近在网上看到一篇介绍android window的requestWindowFeature()的使用方法,共享出来大家学习学习
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.dialog_activity);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,android.R.drawable.ic_dialog_alert);
Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
我们在开发程序是经常会需要软件全屏显示、自定义标题(使用按钮等控件)和其他的需求,今天这一讲就是如何控制Android应用程序的窗体显示.
首先介绍一个重要方法那就是requestWindowFeature(featrueId),它的功能是启用窗体的扩展特性。参数是Window类中定义的常量。
一、枚举常量
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:标题栏右侧的图标
二、详解
1.默认显示状态
2.FEATURE_CUSTOM_TITLE详解
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
这是因为没设置Featrue
在上面代码后加:getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
自定义标题完成,它是一个xml文件布局
title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="文本" />
</LinearLayout>
3.FEATURE_INDETERMINATE_PROGRESS详解
表示一个进程正在运行
实现代码
1.progress.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar android:id="@+id/progress"
android:layout_width="wrap_content"android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
style="?android:attr/progressBarStyleSmallTitle">
</ProgressBar>
</LinearLayout>
2.Java代码
this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);
setProgressBarIndeterminateVisibility(true);
4.FEATURE_LEFT_ICON详解
左侧显示图标
实现代码
this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.main);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);
5.FEATURE_NO_TITLE详解
可用于全屏显示
实现代码
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
虽然上面这样可以在标题栏加入一些控件,但是仍然不能改变标题栏的高度、背景色,要想达到这个目的,只能使用theme(主题)。因此往project里先添加一个style。改变背景色修改android:windowTitleBackgroundStyle的值,改变标题栏高度则修改android:windowTitleSize的值。下面是一个示例:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#778899</item>
</style>
<style name="activityTitlebar" parent="android:Theme">
<item name="android:windowTitleSize">32dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
接着再修改AndroidManifest.xml文件,找到要自定义标题栏的Activity,添加上android:theme值,比如:
<activity android:name=".MainActivity" android:theme="@style/activityTitlebar">
android:theme值就是上面那个style.xml文件里定义的一个style的name值。
按照以上的步骤,修改标题栏布局、高度、背景色的功能就实现了。
相关推荐
NULL 博文链接:https://username2.iteye.com/blog/2183813
(4)Popupwindow没有标题,Dialog默认有标题,可以通过dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);取消标题 (5)二者显示的时候都要设置Gravity。如果不设置,Dialog默认是Gravity.CENTER。 (6)...
requestWindowFeature(Window.FEATURE_NO_TITLE); SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_main); mMapView = (MapView) findViewById(R.id.bmapview); }...
requestWindowFeature(Window.FEATURE_NO_TITLE);//没有标题 window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);// 设置全屏 window.addFlags...
G1的屏幕的分辨率是320×480,虽说不小但也谈不上大,所以有的应用要使用起来,最好还是...12. requestWindowFeature(Window.FEATURE_NO_TITLE); 13. 14. setContentView(R.layout.mylayout); 15. } 摘自anddev
本文主要介绍 Android requestWindowFeature()方法,这里对 requestWindowFeature()方法进行详解,对应用程序窗体显示状态的操作有进一步了解,希望能帮助有需要的小伙伴
requestWindowFeature实验的源码,有助于理解requestWindowFeature
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // 隐去标题栏(程序的名字) setContentView(new MyView(this)); } } 注意: 隐去标题(应用的名字) 此设定必须要写在setContentView...
this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 横竖屏显示 private void ...
一、隐藏标题栏 代码如下: //隐藏标题栏 this.requestWindowFeature(Window.FEATURE_NO_TITLE);二、隐藏状态栏 代码如下: //隐藏状态栏 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,...
requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // 强制为横屏 setRequestedOrientation...
本文实例讲述了Android开发中获取View视图宽与高的常用方法。分享给大家供大家参考,具体如下: 一、根据WindowManager管理器获得 1)这两种方法在屏幕未显示的时候,还是处于0的状态,即要在setContentView调用之后...
在实际的应用程序开发中,我们有时需要把 Activity 设置成全屏显示,一般情况下,可以通过两种方式来设置全屏显示效果: 其一,通过在代码中可以设置, 其二,通过manifest配置文件...requestWindowFeature(Window.FEAT
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); //软件activity的布局 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); //titlebar为自己标题栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE); //取消状态栏 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 第二
requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.splash); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); tv_...
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.custom_title); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1); 这三条语句的次序不能颠倒,...
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏 方法二: 在AndroidManifest.xml 里面设置 <application android:icon=@drawable/icon android:label=@string/app_name Android:theme=@...
本文实例讲述了Android中Activity常用功能设置小结(包括全屏、横竖屏等)。分享给大家供大家参考,具体如下: Activity全屏设置 方式1:AndroidManifest.xml 代码如下:<activity android:name=”myAcitivty” ...