Android自定义标题栏
2011-04-21 11:04
369 查看
本文转自:程序开发技术交流分享
Android程序中默认标题栏是灰色背景,内容是工程名字,类似下图:
修改了标题栏布局,效果如下:
说一下具体步骤。首先,修改标题栏的宽度和背景,在strings.xml中添加:
然后修改AndroidMainfest.xml文件:
红色部分为加载Activity的theme。
接着修改MainActivity:
注意红色部分标记的3行代码,顺序不能颠倒。
最后在layout文件夹中添加title.xml文件,内容如下:
重新部署程序,效果如上图。
源码连接:http://bigcateasymorse.googlecode.com/svn/trunk/androidcustomtitle/
Android程序中默认标题栏是灰色背景,内容是工程名字,类似下图:
修改了标题栏布局,效果如下:
说一下具体步骤。首先,修改标题栏的宽度和背景,在strings.xml中添加:
<style name="CustomWindowTitleBackground"> <item name="android:background">@drawable/title_bg</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>
然后修改AndroidMainfest.xml文件:
<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>
红色部分为加载Activity的theme。
接着修改MainActivity:
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);//自定义布局赋值 }
注意红色部分标记的3行代码,顺序不能颠倒。
最后在layout文件夹中添加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/ic_launcher_email" /> <TextView android:layout_width="wrap_content" android:layout_centerInParent="true" android:layout_height="wrap_content" android:text="自定义标题栏" /> </RelativeLayout>
重新部署程序,效果如上图。
源码连接:http://bigcateasymorse.googlecode.com/svn/trunk/androidcustomtitle/
相关文章推荐
- Android应用开发基础篇(14)-----自定义标题栏
- Android-自定义标题栏
- 解决android自定义标题栏充满的问题
- android 自定义标题栏
- android 自定义view——常用的标题栏
- android 修改窗体标题的字体式样和背景图(自定义标题栏)
- android带返回按钮的自定义标题栏
- [置顶] xamarin android自定义标题栏(自定义属性、回调事件)
- Android 应用程序窗体显示状态操作(显示隐藏标题栏或自定义窗体大小)
- Android自定义实现微信标题栏
- android 自定义标题栏
- Android自定义标题栏
- android自定义标题栏时候you cannot combine custom titles with other title
- Android:自定义标题栏
- Android 自定义标题栏(title栏) .
- Android--自定义标题栏之显示网页加载进度
- android带返回按钮的自定义标题栏
- Android-自定义标题栏
- Android自定义标题栏:显示网页加载进度
- 解决android自定义标题栏充满的问题