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默认

1.FEATURE_CUSTOM_TITLE详解

this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);

图2 无标题

这是因为没设置Featrue

在上面代码后加:getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title); 

 

图3自定义标题

自定义标题完成,它是一个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详解

表示一个进程正在运行

    图4标题进度条显示

实现代码

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);

3.FEATURE_LEFT_ICON详解

左侧显示图标

图5

实现代码


this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.main);

getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);

4.FEATURE_NO_TITLE详解

可用于全屏显示

实现代码

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

图6全屏显示

<!--end: topics 文章、评论容器-->

<!--done-->

更多相关文章

  1. 使用Kotlin:让Android与JS交互的详解
  2. Android(IPC)进程间通讯1:详解Binder由来?
  3. Android(安卓)signed APK程序正式签名方法详解
  4. 【Android】Uri、UriMatcher、ContentUris详解
  5. Android(安卓)Fresco图片加载库基础使用详解
  6. Android横竖屏切换总结
  7. Android(安卓)Scroll详解(二):OverScroller实战
  8. 我的Android进阶之旅------>Android中解析XML 技术详解---->SAX
  9. Android(安卓)Studio 之 Gradle与Project Structure详解

随机推荐

  1. jQuery使用之(四)处理页面的表单元素
  2. 中国省市区地址三级联动jQuery插件
  3. 如果原始页面加载是https,那么没有完整网
  4. 无法理解如何使用javascript和jquery代码
  5. 在不触发hashchange事件的情况下更改哈希
  6. 从事件监听器OnClick中排除按钮
  7. Ajax请求等到第一次AJAX调用未完成
  8. jQuery中$.get、$.post、$.getJSON和$.aj
  9. js或Jquery中判断字符串中是否有换行符或
  10. 如何使用javascript或jquery获取图像的自