Android窗體自定義標題欄

自定義實現功能圖片如下:

<img src="http://dl.iteye.com/upload/picture/pic/103742/6e3dbc72-b70a-3d18-b5ed-129634a7ba25.jpg" alt="" width="440" height="238">

?

?

?

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

<?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

<?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>

?

?

?

<?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>

?




[list]
[*][url=http://dl.iteye.com/topics/download/eaac71fe-cb8c-3364-8c1b-ebd6dec9a8f5]AndroidTitleBar.rar[/url] (57.4 KB)


[*]下載次數: 1

[/list]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章