支持国产操作系统国产应用!

捉蛋网

当前位置: 捉蛋网>教程>Android开发>

Android开发改变窗口标题栏的布局

时间:2013-06-05 16:34来源: 作者: 点击:
  一、重点
  一般应用的Title都是建立应用时在AndroidManifest.xml中配置的,或是用setTitle设置的简单字符串,要是想加入按钮,图片等多个复杂的布局,使用以下方法:

  在窗口建立时,可以把一个xml布局设置成该应用的Title

  二、实例
  a)功能:把title设置成为一个字串和一个按钮的组合

  b)修改xxActivity.java代码
  public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // 注意顺序
           setContentView(R.layout.main);                                                    

                       // 注意顺序
           getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
  // 注意顺序
                              R.layout.title);
  }

  c)填加title.xml代码
  "1.0" encoding="utf-8"?>
    xmlns:android=http://schemas.android.com/apk/res/android
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
        "@+id/text" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_alignParentLeft="true" 
          android:text="text" /> 
  "@+id/button"          android:layout_width="wrap_content"         

  android:layout_height="30px"          android:text="button" />

  三、注意
  a)注意设置顺序requestWindowFeature要在setContentView之前getWindow().setFeatureInit最好在setContentView之后

  b)注意requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)不要和其它对TITLE的设置requestWindowFeature(xxxx)一起使用

(责任编辑:捉蛋网-刷机)
............................................................................................... ...............................................................................................

 

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------