Android改变窗口标题栏的布局
来源:互联网 发布:公众平台源码 编辑:程序博客网 时间:2024/05/17 06:25
一、 重点
一般应用的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)一起使用
一般应用的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)一起使用
- Android改变窗口标题栏的布局
- Android改变窗口标题栏的布局
- Android改变窗口标题栏的布局
- Android改变窗口标题栏的布局
- Android 改变窗口标题栏的布局
- android-改变标题栏布局。
- Android改变标题栏的透明度
- 不改变默认布局样式让Android系统默认的标题栏消失
- android中改变标题栏的背景色
- 改变Java所写窗口的标题栏图标
- Win32 无标题栏 可改变大小的窗口
- 自定义Android标题栏修改TitleBar的布局
- 自定义Android标题栏修改TitleBar的布局
- Android—如何添加布局的标题栏
- android 标题栏布局
- 如何禁止双击标题栏不改变窗口的大小和拖动标题栏窗口不移动的问题
- JavaFx - 窗口的标题栏
- Android改变标题栏背景颜色
- Scrolling CCNode in Cocos2d
- 关于字符指针
- f10
- 过滤XSS(跨站脚本攻击)的函数和防止svn版本库被浏览
- 常用正则表达式验证
- Android改变窗口标题栏的布局
- css+div宽度自适应实例代码
- 中物院计划建国内一流科学仪器研发基地
- 女羽有什么错?
- sql常用语句
- 库存 采购 总账 会计期 是否打开脚本
- 安装Matlab JPEG Toolbox
- 基于Jetty的Comet技术
- RRiBbit 初探