Android中级进阶三 自定义Android标题栏
2012-01-02 15:14
323 查看
最新版本:Android中级进阶三
自定义Android标题栏
原装的Android标题栏配色比较单调,就是黑色的一坨,现在假设你的软件需要独自添加标题栏,这样不仅美观而且可以将进度条等加进去,如何实现:
方法一:
在你的那张Activity中onCreate方法中加上下面代码:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main); //软件activity的布局
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); //titlebar为自己标题栏的布局
但是新的问题又来了,这样是无法深层的定制标题栏的,比如原有的高度和背景都没有发生变化,那有没有好的方法呢?答案是有的、
方法二:
因此先定义一个style,
若修改背景请修改android:windowTitleBackgroundStyle
若修改标题栏高度,请修改android:windowTitleSize
例子:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomWindowTitleBackground">
<item name="android:background">#565656</item>
</style>
<style name="test" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
在程序的android manifest.xml中对应activity中添加属性 android:theme =
"@style/test" 就可以了
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.guardian"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" >
<activity android:name=".Test"
android:label="@string/app_name"
android:theme = "@style/test" //就在这里
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
之后借助于设置自定义的标题栏xml文件,就可以自定义标题栏布局了
自定义Android标题栏
原装的Android标题栏配色比较单调,就是黑色的一坨,现在假设你的软件需要独自添加标题栏,这样不仅美观而且可以将进度条等加进去,如何实现:
方法一:
在你的那张Activity中onCreate方法中加上下面代码:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main); //软件activity的布局
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); //titlebar为自己标题栏的布局
但是新的问题又来了,这样是无法深层的定制标题栏的,比如原有的高度和背景都没有发生变化,那有没有好的方法呢?答案是有的、
方法二:
因此先定义一个style,
若修改背景请修改android:windowTitleBackgroundStyle
若修改标题栏高度,请修改android:windowTitleSize
例子:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomWindowTitleBackground">
<item name="android:background">#565656</item>
</style>
<style name="test" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
在程序的android manifest.xml中对应activity中添加属性 android:theme =
"@style/test" 就可以了
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.guardian"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" >
<activity android:name=".Test"
android:label="@string/app_name"
android:theme = "@style/test" //就在这里
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
之后借助于设置自定义的标题栏xml文件,就可以自定义标题栏布局了
相关文章推荐
- android界面之自定义标题栏
- Android 如何自定义一个简单的组件和自定义的点击事件(中级)
- android自定义标题栏,解决背景颜色…
- Android进阶学习-属性动画与自定义属性
- Android项目中自定义顶部标题栏
- 自定义Android手机的Activity标题栏
- Android进阶之自定义view(二)
- Android自定义标题栏
- Android实现自定义标题栏的方法
- Android Study之自定义View进阶路:绘制饼图(二)
- Android自定义title标题栏
- Android 自定义View (二) 进阶
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- Android高手进阶教程(三)之----Android 中自定义View的应用.
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- 【Android UI设计与开发】第13期:顶部标题栏(四)自定义ActionBar风格和样式 .
- Android UI设计——ViewPage中自定义标题栏(四)
- Android 自定义Activity标题栏之requestWindowFeature()的应用
- 初识Android之(一)-自定义标题栏控件