Android改变窗口标题栏的布局


第一种方式

--在XML文件里面引入配置文件作为标题。

第二种方式

--动态的代码加入进去。


第三种方式(网上的):

一、 重点
一般应用的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代码
<?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">
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="text" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="30px"
android:text="button" />
</LinearLayout>

三、 注意

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

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

更多相关文章

  1. (二)Unity 与 Android的布局管理
  2. .Net码农学Android---五分钟了解布局
  3. 安卓实战开发之CardView的selector及GrideView的item按下状态保
  4. 什么时候会启动多个进程
  5. android 系统解耦思想-设置与framework
  6. Android软件开发之盘点界面五大布局(十六)
  7. 如何恢复(初始化)android studio所有设置
  8. Delphi/C++ Builder 开发 Android(安卓)程序启动画面简单完美解
  9. Android中View绘图总结

随机推荐

  1. 互联网公司Android客户端面试 知识点
  2. android(EditText)属性详解
  3. Android NDK开发:SeetaFace2实现人脸匹配
  4. Android 开发——'Android Pre Compiler'
  5. 2.高焕堂讲解 ContentProvider范例
  6. android使用http协议上传文件
  7. Android应用正确使用扩展SD卡
  8. Android ApiDemos示例解析(15):App->Activ
  9. MPAndroidChart项目实战(二)——双平滑曲线
  10. Android 虚拟机及其GC机制