博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android-自己定义标题栏
阅读量:6949 次
发布时间:2019-06-27

本文共 2398 字,大约阅读时间需要 7 分钟。

Android-自己定义标题栏

2014年4月25日 分享知识点

最近也比較多事情,想发发博客就是心有余而力不足睡觉,本篇博文主要教大家怎样实现自己定义标题栏,非常easy。那么聪明的你一下就看懂。

有兴趣能够加一下 群号是299402133,里面有丰富的学习资源,志同道合的你。一定会有所收获的。

实现步骤

* 1、给自己定义标题提供一个界面 

* 2、将自己定义标题应用给Activity窗体 

* 3、把android系统为Activity设置的默认主题改为自己的主题

效果图:

代码下载:

/02_CustomTitle/res/layout/constom_title.xml

> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rectangle" android:orientation="horizontal" > <!-- 指定背景。该背景自己画的 --> <TextView style="@android:style/TextAppearance.Medium" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="IT_xiao小巫" android:textColor="#ffffff" android:textSize="14sp" /> </LinearLayout>

这里使用到了一个图像资源,是在drawable文件夹下的:

/02_CustomTitle/res/drawable/rectangle.xml

/02_CustomTitle/src/com/wwj/constomtitle/MainActivity.java
package com.wwj.constomtitle;import android.app.Activity;import android.os.Bundle;import android.view.Window;/** * 1、给自己定义标题提供一个界面  * 2、将自己定义标题应用给Activity窗体  * 3、把android系统为Activity设置的默认主题改为自己的主题 *  * @author wwj *  */public class MainActivity extends Activity {	@Override	protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);				// 指定使用自己定义标题		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);		setContentView(R.layout.activity_main);		// 设置窗体的自己定义标题布局文件		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.constom_title);			}}
改动默认样式

/02_CustomTitle/res/values/drawable.xml

 
#00000000
在AndroidManifest.xml设置主题
 

> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wwj.constomtitle" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/customTheme" > <activity android:name="com.wwj.constomtitle.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

 

你可能感兴趣的文章
Mysql压缩包版zip的安装方法
查看>>
UWP 动画
查看>>
浅析设计模式(二)——工厂方法模式
查看>>
面试宝典-面试题1
查看>>
DAY1 linux 50条命令
查看>>
Eclipse设置Tab键为四个空格
查看>>
Windows漏洞利用技术概述
查看>>
多态与接口
查看>>
HTML5标准学习 - 文档结构
查看>>
zookeeper练习
查看>>
最短路径
查看>>
手机评测
查看>>
java ssm 后台框架平台 项目源码 websocket 即时通讯 IM quartz springmvc
查看>>
我的小爬虫—cocoa 中的正则表达式
查看>>
HTML5 中 div 和section以及 article 的不同之处
查看>>
Yii2学习笔记之场景
查看>>
CS Website
查看>>
docker - 容器里安装ssh
查看>>
Ant design 组件开发
查看>>
完整性约束
查看>>