博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 改变窗口标题栏的布局
阅读量:4306 次
发布时间:2019-06-06

本文共 1265 字,大约阅读时间需要 4 分钟。

 

第一种方式

--在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)一起使用

 

转载于:https://www.cnblogs.com/new0801/p/6175816.html

你可能感兴趣的文章
JVM内存管理及GC机制
查看>>
Java:按值传递还是按引用传递详细解说
查看>>
Java中Synchronized的用法
查看>>
阻塞队列
查看>>
linux的基础知识
查看>>
接口技术原理
查看>>
五大串口的基本原理
查看>>
PCB设计技巧与注意事项
查看>>
linux进程之间通讯常用信号
查看>>
main函数带参数
查看>>
PCB布线技巧
查看>>
关于PCB设计中过孔能否打在焊盘上的两种观点
查看>>
PCB反推理念
查看>>
京东技术架构(一)构建亿级前端读服务
查看>>
php 解决json_encode中文UNICODE转码问题
查看>>
LNMP 安装 thinkcmf提示404not found
查看>>
PHP empty、isset、innull的区别
查看>>
apache+nginx 实现动静分离
查看>>
通过Navicat远程连接MySQL配置
查看>>
phpstorm开发工具的设置用法
查看>>