Android-自定义标题栏
来源:互联网 发布:淘宝付款方式怎么删除 编辑:程序博客网 时间:2024/05/16 14:01
Android-自定义标题栏
实现步骤
* 1、给自定义标题提供一个界面
* 2、将自定义标题应用给Activity窗口
* 3、把android系统为Activity设置的默认主题改为自己的主题
效果图:
代码下载:http://download.csdn.net/detail/wwj_748/7249585
/02_CustomTitle/res/layout/constom_title.xml
- <?xml version="1.0" encoding="utf-8"?>
- <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
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle" >
- <!-- 定义渐变色 -->
- <gradient
- android:angle="270"
- android:endColor="#80FF00FF"
- android:startColor="#FFFF0000" />
- <!-- 定义控件内容到边界的距离(到四条边界的距离都是2) -->
- <padding
- android:bottom="2dp"
- android:left="2dp"
- android:right="2dp"
- android:top="2dp" />
- <!-- 定义圆角 -->
- <corners android:radius="8dp" />
- </shape>
- 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);
- }
- }
修改默认样式
- <!-- 该样式继承系统的默认样式 -->
- <style name="customTheme" parent="android:Theme">
- <!-- 设置标题前景色为透明 -->
- <item name="android:windowContentOverlay">@drawable/nocolor</item>
- <!-- 设置标题高度为44dp -->
- <item name="android:windowTitleSize">44dp</item>
- <!-- 设置标题背景色 -->
- <item name="android:windowTitleBackgroundStyle">@style/customBg</item>
- </style>
- <!-- 定义一个背景样式 -->
- <style name="customBg">
- <item name="android:background">@drawable/rectangle</item>
- </style>
/02_CustomTitle/res/values/drawable.xml
- <pre code_snippet_id="311163" snippet_file_name="blog_20140425_5_585886" name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
- <resources>
- <!-- 定义一个透明色 -->
- <drawable name="nocolor">#00000000</drawable>
- </resources></pre><br><br>
- 在AndroidManifest.xml设置主题
- <pre code_snippet_id="311163" snippet_file_name="blog_20140425_7_8154861" name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
- <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>
0 0
- android自定义标题栏progressBar
- Android自定义标题栏
- 自定义android标题栏
- android实现自定义标题栏
- Android自定义标题栏
- Android 自定义标题栏
- Android 自定义标题栏
- Android自定义标题栏
- Android自定义标题栏
- android之自定义标题栏
- Android自定义标题栏
- Android 自定义标题栏运用
- Android 自定义标题栏
- android ListView+自定义标题栏
- Android 自定义标题栏
- Android:自定义标题栏
- Android Actionbar自定义标题栏
- 自定义Android标题栏TitleBar
- 日经春秋 20150119
- 折半查找法(递归)
- iOS-Core-Animation之八----显式动画
- UVA 10617
- InternetExplorer Object
- Android-自定义标题栏
- Eclipse/MyEclipse设置在保存文件时自动调用Ant脚本执行一些构建操作
- 原型制作工具Axure的优点和使用人群
- 一个Axure学习交流的网站
- 日经社説 20150119 働きやすい保育の職場に
- Axure RP 基本功能介绍
- 闲时整理(3)------消息提示标签 BadgeView
- Axure RP ;交互设置三要素/要素设置…
- Axure RP 内部框架的使用