修改系统标题栏 高度 字体偏移 添加图片 点击事件
2017-03-21 14:45
423 查看
修改系统标题栏 高度 字体偏移 添加图片 点击事件
具体的操作步骤是: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
plain copy
<?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
plain copy
<?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>
<
item
name
=
"Android:windowTitleSize"
>60dp</
item
><!-- 标题栏高度 -->
</style>
</resources>
5、修改工程的Manifest.xml文件
.在Activity中加入android:theme="@style/titleTheme"即可
[xhtml] view
plain copy
<?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、效果图
7、改变文字的位置
经过上面的设置可以实现蓝色背景,高度40dp的标题栏,但是此时标题还没有居中。我曾经尝试在style中通过设置android:gravity=center等方式,但都没有成功。
后来在activity的代码中添加以下代码才实现了居中效果:
[java] view
plain copy
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview1= (TextView) findViewById(android.R.id.title);view.setGravity(Gravity.CENTER);
//此处添加点击事件
//添加图片
Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);
nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
textview1.setCompoundDrawables(null, null, nav_up, null);
[java] view
plain copy
setContentView(R.layout.activity_main);
...
}
相关文章推荐
- UIWebView添加图片点击事件、调整字体大小与高度自适应的解决方法
- iOS开发之--如何修改TabBarItem的title的字体和颜色/BarButtonItem的title的字体大小和颜色/添加背景图片,并添加点击方法
- Android中WebView加载Html中的图片添加点击事件
- Qt:添加点击事件的Label并显示图片
- 在mac系统安装Apache Tomcat的详细步骤(转载自himi的博客,修改了错误添加了图片)
- 图片添加点击事件
- 用axure给按钮图片等添加点击事件跳转页面
- actionBar添加action图片和点击事件
- 前台 jquery通过点击事件添加数量,并异步请求修改
- Android TextView加载HTMl图文之添加点击事件和查看图片
- 在Edittext中添加图片并为图片添加点击事件
- Qt为QLabel添加点击事件-使QLabel成为一个图片按钮
- ubuntu16.04 xfce4的鼠标主题设置为oxygen-red、修改文件夹背景颜色、两处系统字体设置、右键菜单添加压缩解压选项
- 154在屏幕中绘图时设置透明度(扩展知识:为图片视图添加点击手势识别器,来实现点击事件操作)
- textview不同颜色字体点击事件图片2
- c# 给button添加不规则的图片以及用pictureBox替代button响应点击事件的方法
- iOS UIImageView图片添加点击事件
- 在Android中ListView中添加两个点击事件,一个是OnItemClick,另一个是一个图片的OnClick事件
- 遍历指定目录下的图片文件 显示在gridview 并添加点击事件