Android ApiDemo示例解读5:Activity->Custom Title

移动开发 Android
Android允许Activity自定义标题栏,使用自定义Layout重新设置标题栏,App->Activity->Custom Title 重新将Activity标题栏定义为左右两个文本框。

Android UI缺省的标题栏由android:label 定义,显示在屏幕左上角,Android允许Activity自定义标题栏,使用自定义Layout重新设置标题栏,比如实现Windows Mobile 风格的标题栏。

App->Activity->Custom Title 重新将Activity标题栏定义为左右两个文本框,其Layout定义R.layout.custom_title_1如下:

(下面的xml中包含了一左一右两个文本框。

与每个Activity对应的除了使用由setContentView设置的Content View之外,还有一个Windows类对象,Windows 类对象用于控制标题栏,可以允许自定义标题栏或是不显示标题栏。)

  1. <RelativeLayout   
  2.  xmlns:android=”http://schemas.android.com/apk/res/android”   
  3.  android:id=”@+id/screen”   
  4.  android:layout_width=”match_parent”   
  5.  android:layout_height=”match_parent”   
  6.  android:orientation=”vertical”>   
  7.  <TextView android:id=”@+id/left_text”   
  8.  android:layout_width=”wrap_content”   
  9.  android:layout_height=”wrap_content”   
  10.  android:layout_alignParentLeft=”true”   
  11.  android:text=”@string/custom_title_left” />   
  12.  <TextView android:id=”@+id/right_text”   
  13.  android:layout_width=”wrap_content”   
  14.  android:layout_height=”wrap_content”   
  15.  android:layout_alignParentRight=”true”   
  16.  android:text=”@string/custom_title_right” />   
  17.  </RelativeLayout>   

Windows 定义了一些Feature,允许开发人员做些定制:自定义标题栏对应的Feature ID为Window.FEATURE_CUSTOM_TITLE。

  1. requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);   
  2. setContentView(R.layout.custom_title);   
  3. getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);   

Android ApiDemo示例解读系列之五:App->Activity->Custom Title

 

责任编辑:闫佳明 来源: jizhuomi
相关推荐

2013-12-19 14:13:16

Android ApiAndroid开发Android SDK

2013-12-19 14:32:31

Android ApiAndroid开发Android SDK

2013-12-19 14:34:52

Android ApiAndroid开发Android SDK

2013-12-19 14:36:43

Android ApiAndroid开发Android SDK

2013-12-19 14:28:04

Android ApiAndroid开发Android SDK

2013-12-19 14:00:39

Android ApiAndroid开发Android SDK

2013-12-19 13:40:44

Android ApiAndroid开发Android SDK

2013-12-19 13:51:12

Android ApiAndroid开发Android SDK

2013-12-19 16:26:29

Android ApiAndroid开发Android SDK

2010-02-02 14:22:50

Python示例

2014-05-27 14:33:37

AndroidActivitysingleTask

2010-02-01 11:22:09

C++虚函数

2013-01-08 13:33:07

Android开发Activity入门指南

2010-03-05 10:47:05

Python futu

2010-03-02 14:41:00

WCF行为控制

2012-02-17 17:07:30

Android安全Activity劫持

2015-10-20 15:54:16

android源码滑动关闭

2010-02-04 16:07:39

C++回调函数

2010-01-04 17:03:27

Silverlight

2010-02-06 10:14:36

Android Act
点赞
收藏

51CTO技术栈公众号