android 修改窗体标题的字体式样和…
2014-04-18 11:58
211 查看
自定义一个layout,然后通过requestWindowFeature和getWindow().setFeatureInt方法调用,
但是存在填充不满的问题,而且比较麻烦。
但是,我只是想改变标题栏字体的大小、颜色,并设置一个背景图片,并不想定义一个layout的xml文件。
那么,android有没有提供解决上述问题的方法呢,答案是肯定的,一定可以。
默认的标题栏式样太难看了,灰不啦吉的。
后来参考了一篇洋人博友的文章,最终有所收获。
http://zaman91.wordpress.com/2010/03/18/android-how-to-customize-default-themes-and-styles/
具体的操作步骤是:
1、在res/values添加styles.xml文件。
.在eclipse中,选择File -> New ->
Other菜单
.在弹出窗口中,选择Android/Android XML File,点击 Next
.在添加XML窗口中,输入文件名"styles.xml",选中Values,
输入文件夹路径"/res/values"
.然后点击 Finish
2、在res/values添加themes.xml文件。
操作方法同步骤1,只是文件名输入"themes.xml"
3、styles.xml文件的代码
[xhtml] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:adnroid="http://schemas.android.com/apk/res/android">
<style name="CustomWindowTitleBackground" parent="android:WindowTitleBackground">
<item name="android:background">@drawable/bg</item>
</style>
<style name="CustomWindowTitle" parent="android:WindowTitle">
<item name="android:textAppearance">@style/CustomWindowTitleText</item>
</style>
<style name="CustomWindowTitleText" parent="android:TextAppearance.WindowTitle">
<item name="android:textColor">#00f</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
4、themes.xml文件的代码
[xhtml] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:adnroid="http://schemas.android.com/apk/res/android">
<style name="titleTheme" parent="android:Theme" >
<!-- <item name="android:windowTitleSize">30dp</item> -->
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
<item name="android:windowTitleStyle">@style/CustomWindowTitle</item>
</style>
</resources>
5、修改工程的Manifest.xml文件
.在Activity中加入android:theme="@style/titleTheme"即可
[xhtml] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.customtitle"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".CustomTitle"
android:label="@string/app_name"
android:theme="@style/titleTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
6、效果图
说明:
.关于@drawable/bg,它是title的背景图. bg.png格式。
直接在res目录下创建修文件夹drawable及文件bg.png即可。
.个人感觉,android的所有style和theme都是可以继承并且修改的。
关于style和theme的详细,可以查看一下的参考资料。
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/styles.xml
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/themes.xml
但是存在填充不满的问题,而且比较麻烦。
但是,我只是想改变标题栏字体的大小、颜色,并设置一个背景图片,并不想定义一个layout的xml文件。
那么,android有没有提供解决上述问题的方法呢,答案是肯定的,一定可以。
默认的标题栏式样太难看了,灰不啦吉的。
后来参考了一篇洋人博友的文章,最终有所收获。
http://zaman91.wordpress.com/2010/03/18/android-how-to-customize-default-themes-and-styles/
具体的操作步骤是:
1、在res/values添加styles.xml文件。
.在eclipse中,选择File -> New ->
Other菜单
.在弹出窗口中,选择Android/Android XML File,点击 Next
.在添加XML窗口中,输入文件名"styles.xml",选中Values,
输入文件夹路径"/res/values"
.然后点击 Finish
2、在res/values添加themes.xml文件。
操作方法同步骤1,只是文件名输入"themes.xml"
3、styles.xml文件的代码
[xhtml] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:adnroid="http://schemas.android.com/apk/res/android">
<style name="CustomWindowTitleBackground" parent="android:WindowTitleBackground">
<item name="android:background">@drawable/bg</item>
</style>
<style name="CustomWindowTitle" parent="android:WindowTitle">
<item name="android:textAppearance">@style/CustomWindowTitleText</item>
</style>
<style name="CustomWindowTitleText" parent="android:TextAppearance.WindowTitle">
<item name="android:textColor">#00f</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
4、themes.xml文件的代码
[xhtml] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:adnroid="http://schemas.android.com/apk/res/android">
<style name="titleTheme" parent="android:Theme" >
<!-- <item name="android:windowTitleSize">30dp</item> -->
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
<item name="android:windowTitleStyle">@style/CustomWindowTitle</item>
</style>
</resources>
5、修改工程的Manifest.xml文件
.在Activity中加入android:theme="@style/titleTheme"即可
[xhtml] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.customtitle"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".CustomTitle"
android:label="@string/app_name"
android:theme="@style/titleTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
6、效果图
说明:
.关于@drawable/bg,它是title的背景图. bg.png格式。
直接在res目录下创建修文件夹drawable及文件bg.png即可。
.个人感觉,android的所有style和theme都是可以继承并且修改的。
关于style和theme的详细,可以查看一下的参考资料。
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/styles.xml
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/themes.xml
相关文章推荐
- android 修改窗体标题的字体式样和…
- android 修改窗体标题的字体式样和背景图(自定义标题栏)
- Android原生AlertDialog修改标题,内容,按钮颜色,字体大小等
- Android修改Toolbar标题和菜单项字体大小和颜色
- android&nbsp;状态栏透明,源码修改教程
- Android&nbsp;系统初始值修改
- android:修改PagerTabStrip中的背景颜色,标题字体的样式、颜色和图标以及指示条的颜色
- android使用自定义标题时提示“you cannot combine custom titles with other  ”
- android:修改PagerTabStrip中的背景颜色,标题字体的样式、颜色和图标以及指示条的颜色
- Android原生AlertDialog修改标题,内容,按钮颜色,字体大小等
- 增加工具栏提示&修改程序字体&设置文档标题&控制窗口显示&更新菜单选中/不选中状态
- Android-->沉浸式状态栏字体颜色的修改(只针对小米和魅族)
- Flash&nbsp;Builder&nbsp;注释字体修改
- Xamarin Android 中修改 TabbedPage 标题字体
- 修改背景颜色&字体&窗口标题及大小
- android&nbsp;项目编码修改,&amp;nbsp…
- Android 系统默认参数的修改(一)
- 转:MTK&nbsp;Android&nbsp;修改默认日期时间
- Android 系统默认参数的修改(二)
- Android Tablayout + viewpager 切换时修改tablayout title(标题)的字体颜色和字体大小