android自定义标题栏
2013-12-18 11:04
302 查看
第一步:创建自定义标题栏的布局文件
第二步:创建自定义Style文件(res/values/style.xml)
第三步:AndroidMainfest.xm引用自定义的Style文件
第四步:Actiivty创建自定义标题栏
效果展示:
<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="48dp" > <Button android:id="@+id/title_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_marginLeft="8dp" android:layout_marginTop="10dp" android:background="@drawable/back" android:text=" 返回" android:textColor="#858585" android:textSize="16dp" /> <TextView android:id="@+id/title_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/back" android:layout_centerInParent="true" android:layout_alignBottom="@+id/back android:text="首页" android:textColor="#858585" android:textSize="24dp" android:layout_marginTop="10dp" ></TextView> <Button android:id="@+id/title_function" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="8dp" android:layout_marginTop="10dp" android:background="@drawable/back" android:text="功能" android:textColor="#858585" android:textSize="16dp" ></Button> </RelativeLayout>
第二步:创建自定义Style文件(res/values/style.xml)
<style name="CustomWindowTitleBackground"> <item name="android:background">@drawable/title_style</item> </style> <style name="titlewindowstyle" parent="android:Theme"> <item name="android:windowTitleSize">45dp</item> <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item> </style>
第三步:AndroidMainfest.xm引用自定义的Style文件
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.vixuan.swxm" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="11" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/titlewindowstyle" ><!-- 重点--> <activity android:name="com.vixuan.swxm.activity.LoginActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.vixuan.swxm.activity.MainActivity" android:label="@string/app_name" > </activity> </application> </manifest>
第四步:Actiivty创建自定义标题栏
package com.vixuan.swxm.activity; import com.vixuan.swxm.R; import android.app.Activity; import android.os.Bundle; import android.view.Window; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // 自定义窗口标题的样式 注意顺序 setContentView(R.layout.activity_main); MainActivity.this.getWindow().setFeatureInt( Window.FEATURE_CUSTOM_TITLE, R.layout.title_style);// 注意顺序 } }
效果展示:
相关文章推荐
- android - 自定义标题栏(在标题栏中增加按钮和文本居中)
- Android 开发之自定义标题栏、状态栏
- Android自定义标题栏
- 【Android UI设计与开发】第13期:顶部标题栏(四)自定义ActionBar风格和样式
- android 自定义标题栏
- 自定义Android标题栏修改TitleBar的布局
- 【Android UI设计与开发】第13期:顶部标题栏(四)自定义ActionBar风格和样式
- Android---自定义标题栏
- android标题栏颜色的自定义,文本居中
- android自定义标题栏progressBar
- Android 自定义全局标题栏 解决输入法遮住屏幕问题
- 【Android UI设计与开发】第13期:顶部标题栏(四)自定义ActionBar风格和样式
- Android自定义标题栏
- [置顶] Android--(13)--Android自定义实现actionbar实现微信标题栏
- android自定义标题栏,解决背景颜色…
- 初识Android之(一)-自定义标题栏控件
- Android 自定义标题栏
- Android高级UI之自定义复合控件--标题栏
- Android中自定义ScrollView的滑动监听事件,并在滑动时渐变标题栏背景颜色
- 自定义 android 标题栏