Android窗体自定义标题栏
2012-01-16 15:31
267 查看
自定义实现功能图片如下:
![](http://dl.iteye.com/upload/picture/pic/103742/6e3dbc72-b70a-3d18-b5ed-129634a7ba25.jpg)
Java代码
![](http://topmanopensource.iteye.com/images/icon_star.png)
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"管理对应的样式
*
* <activity android:name=".MainActivity"
* android:theme="@style/test">
* <intent-filter>
* <action android:name="android.intent.action.MAIN" />
* <category android:name="android.intent.category.LAUNCHER" />
* </intent-filter>
* </activity>
*
* @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
Java代码
![](http://topmanopensource.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, AndroidTitleBarActivity!</string>
<string name="app_name">AndroidTitleBar</string>
<style name="CustomWindowTitleBackground">
<item name="android:background">@drawable/logo</item>
</style>
<style name="test" parent="android:Theme" mce_bogus="1">
<item name="android:windowTitleSize">40dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
title.xml
Java代码
![](http://topmanopensource.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:src="@drawable/qq" />
<TextView android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:text="自定义标题栏" />
</RelativeLayout>
Java代码
![](http://topmanopensource.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.easyway.titlebar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!--
主题信息定义在values/strings.xml文件中
android:theme="@style/test"
-->
<activity
android:label="@string/app_name"
android:theme="@style/test"
android:name=".AndroidTitleBarActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
AndroidTitleBar.rar (57.4 KB)
![](http://dl.iteye.com/upload/picture/pic/103742/6e3dbc72-b70a-3d18-b5ed-129634a7ba25.jpg)
Java代码
![](http://topmanopensource.iteye.com/images/icon_star.png)
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"管理对应的样式
*
* <activity android:name=".MainActivity"
* android:theme="@style/test">
* <intent-filter>
* <action android:name="android.intent.action.MAIN" />
* <category android:name="android.intent.category.LAUNCHER" />
* </intent-filter>
* </activity>
*
* @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
Java代码
![](http://topmanopensource.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, AndroidTitleBarActivity!</string>
<string name="app_name">AndroidTitleBar</string>
<style name="CustomWindowTitleBackground">
<item name="android:background">@drawable/logo</item>
</style>
<style name="test" parent="android:Theme" mce_bogus="1">
<item name="android:windowTitleSize">40dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
title.xml
Java代码
![](http://topmanopensource.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:src="@drawable/qq" />
<TextView android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:text="自定义标题栏" />
</RelativeLayout>
Java代码
![](http://topmanopensource.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.easyway.titlebar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!--
主题信息定义在values/strings.xml文件中
android:theme="@style/test"
-->
<activity
android:label="@string/app_name"
android:theme="@style/test"
android:name=".AndroidTitleBarActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
AndroidTitleBar.rar (57.4 KB)
相关文章推荐
- Android 应用程序窗体显示状态操作(显示隐藏标题栏或自定义窗体大小)
- Android 应用程序窗体显示状态操作(显示隐藏标题栏或自定义窗体大小)
- android 修改窗体标题的字体式样和背景图(自定义标题栏)
- Android 应用程序窗体显示状态操作(显示隐藏标题栏或自定义窗体大小)
- 【Android UI设计与开发】第13期:顶部标题栏(四)自定义ActionBar风格和样式
- Android 自定义标题栏
- Android自定义标题栏并实现沉浸式
- 自定义Android标题栏修改TitleBar的布局
- (转自ztp800201) Android - 自定义标题栏(在标题栏中增加按钮和文本居中)
- android界面之自定义标题栏
- Android自定义标题栏
- 解决android自定义标题栏充满的问题
- Android随笔之标题栏的去除以及自定义
- android自定义标题栏
- Android自定义标题栏
- android自定义标题栏,解决背景颜色…
- 解决android自定义标题栏充满的问题
- 转:自定义Android标题栏TitleBar
- Android 实现横向标题栏滚动效果(HorizontalScrollView + GridView + Viewpager + 自定义适配器)
- Android封装一个自定义标题栏