java怎么设置窗体标题_Android窗体自定义标题栏

本文介绍如何在Android应用中实现自定义窗体标题栏,通过设置Window.FEATURE_CUSTOM_TITLE来声明使用自定义标题,并在Activity中设置相关样式,同时提供了一段示例代码进行演示。
摘要由CSDN通过智能技术生成

自定义实现功能图片如下:

?

?

?

package com.easyway.titlebar;

import android.app.Activity;

import android.os.Bundle;

import android.view.Window;

/**

* 自定义窗体标签的样式表格式的使用

* 1.设置window标题信息

* requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题

* setContentView(R.layout.main);

* //设置窗体样式

* getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//自定义布局赋值

* 2.在对应的Activity中添加相关的 android:theme="@style/test"管理对应的样式

*

*

* android:theme="@style/test">

*

*

*

*

*

*

* @author longgangbai

*

*/

public class AndroidTitleBarActivity extends Activity {

/** Called when the activity is first created. */

@Override

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 //设置对应的布局

);//自定义布局赋值

}

}

?

?

strings.xml

Hello World, AndroidTitleBarActivity!

AndroidTitleBar

@drawable/logo

40dp

@style/CustomWindowTitleBackground

?

?

title.xml

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_centerVertical="true"

android:layout_height="wrap_content"

android:src="@drawable/qq" />

android:layout_centerInParent="true"

android:layout_height="wrap_content"

android:text="自定义标题栏" />

?

?

?

package="com.easyway.titlebar"

android:versionCode="1"

android:versionName="1.0" >

android:icon="@drawable/ic_launcher"

android:label="@string/app_name" >

android:label="@string/app_name"

android:theme="@style/test"

android:name=".AndroidTitleBarActivity" >

?

AndroidTitleBar.rar (57.4 KB)

下载次数: 1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值