Android程序窗体显示:requestWindowFeature()

[b][size=large]本文围绕以下五个部分展开: [/size][/b]

[b][size=large]一、requestWindowFeature()[/size][/b]
[b][size=large]二、FEATURE_CUSTOM_TITLE:自定义标题[/size][/b]
[b][size=large]三、FEATURE_INDETERMINATE_PROGRESS[/size][/b]
[b][size=large]四、FEATURE_LEFT_ICON[/size][/b]
[b][size=large]五、FEATURE_NO_TITLE[/size][/b]


[b][size=large]一、requestWindowFeature()[/size][/b]

[size=medium]我们在开发Android应用程序时经常会需要软件全屏显示、自定义标题(使用按钮等控件)或其他的需求,因此需要掌握Android应用程序窗体显示的方法。[/size]

[size=medium]一个重要方法就是:requestWindowFeature(featrueId)。它的功能是启用窗体的扩展特性,参数是Window类中定义的常量。[/size]

[align=center][img]http://dl2.iteye.com/upload/attachment/0111/6634/44c0b2a4-d190-38b7-8e76-208f83d3713d.png[/img][/align]


[b][size=large]二、FEATURE_CUSTOM_TITLE:自定义标题[/size][/b]

        // 自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);


[size=medium]customtitle.xml。[/size]

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本" />

</LinearLayout>


[align=center][img]http://dl2.iteye.com/upload/attachment/0111/6646/0a2aecc1-9f0a-3aff-9e79-ed17777aa436.png[/img][/align]


[b][size=large]三、FEATURE_INDETERMINATE_PROGRESS[/size][/b]

        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);
// 必须得加上否则显示不出效果 可以通过这个在以后设置显示或隐藏
setProgressBarIndeterminateVisibility(true);


[size=medium]progress.xml。[/size]

<?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"
android:orientation="vertical">

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


[align=center][img]http://dl2.iteye.com/upload/attachment/0111/6650/acb85783-993e-31d5-84a0-6d20bc1919bd.png[/img][/align]


[b][size=large]四、FEATURE_LEFT_ICON[/size][/b]

        requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_LEFT_ICON, R.mipmap.ic_launcher);


[align=center][img]http://dl2.iteye.com/upload/attachment/0111/6654/9519dcae-e8f8-3a67-97fb-e6e1c44500cd.png[/img][/align]


[b][size=large]五、FEATURE_NO_TITLE[/size][/b]

        requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
// 加上这句设置为全屏 不加则只隐藏title
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);


[align=center][img]http://dl2.iteye.com/upload/attachment/0111/6656/e8043121-e6a4-358a-9034-9ac41fba4faf.png[/img][/align]


[size=medium][b]整理时参考:[/b][/size]
[size=medium][color=red]http://www.cnblogs.com/salam/archive/2010/11/30/1892143.html[/color][/size]
[size=medium][color=red]http://zhanhao.iteye.com/blog/1174914[/color][/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值