android编程更改标题,Android编程实现自定义title功能示例

本文实例讲述了Android编程实现自定义title功能。分享给大家供大家参考,具体如下:

dc2d6b5f0935c6603687a25d4af20223.png

这里我在前面加了个logo,而且改变了title的背景和高度。

首先编写title的布局文件,title.xml:

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/bg_title"

android:gravity="center_vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/title_logo"

/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/app_name"

android:textSize="20sp"

android:layout_marginLeft="80dip"

android:textColor="#ffffff"

/>

然后在Activity的onCreate()里加上这三句话:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);

需要注意的是这三句话的顺序不能变。到这里只是改变了title的布局,下面改变背景和高度,这就需要改变Activity的theme。

在values文件夹下新建文件style.xml:

@drawable/bg_title

44dip

@style/CustomWindowTitleBackground

最后在AndroidManifest.xml里面加上:

android:label="@string/app_name"

android:screenOrientation="portrait"

android:theme="@style/title_style"

>

这样就实现了自定义title。

希望本文所述对大家Android程序设计有所帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值