实现自定义窗口title
来源:互联网 发布:淘宝快手直播号能买吗? 编辑:程序博客网 时间:2024/06/05 18:10
第一步,实现自定义标题栏,需要在onCreate方法里这样写
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
注意:requestWindowFeature方法要在setContentView方法之前,getWindow().setFeatureInit最好在setContentView方法之后
第二步,就是写好自己的布局文件,实现标题栏的自定义:title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/title_bg" >
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dip"
android:textColor="#000"
android:text="@string/app_label"
android:layout_gravity="center_vertical"/>
</LinearLayout>
第三步,写一个style:velue/style.xml
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#CCFFFF</item>
</style>
<style name="activityTitlebar" parent="android:Theme">
<item name="android:windowTitleSize">45dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
第四步,把style加入到AndroidManifest.xml
<activity android:name=".DemoActivity"
android:label="@string/app_name" android:theme="@style/activityTitlebar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
注意:requestWindowFeature方法要在setContentView方法之前,getWindow().setFeatureInit最好在setContentView方法之后
第二步,就是写好自己的布局文件,实现标题栏的自定义:title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/title_bg" >
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dip"
android:textColor="#000"
android:text="@string/app_label"
android:layout_gravity="center_vertical"/>
</LinearLayout>
第三步,写一个style:velue/style.xml
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#CCFFFF</item>
</style>
<style name="activityTitlebar" parent="android:Theme">
<item name="android:windowTitleSize">45dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
第四步,把style加入到AndroidManifest.xml
<activity android:name=".DemoActivity"
android:label="@string/app_name" android:theme="@style/activityTitlebar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
- 实现自定义窗口title
- 自定义title实现
- Android自定义Title的实现
- 实现卫星菜单和自定义title
- 自定义Title
- 自定义Title
- 自定义title
- 自定义title
- 自定义title
- 实现输入法窗口自定义
- 自定义的窗口消息实现
- UpdateLayeredWindow实现自定义透明窗口
- 自定义Dialog 实现弹出窗口
- JS+DIV实现自定义Title的显示方式
- 自定义ViewGroup实现Title自动隐藏功能(带源代码)
- 自定义的Title
- 链接title自定义效果
- 自定义TITLE提示效果
- nyoj 108 士兵杀敌(一)
- C++编程学习50个经典网站 强力推荐
- HTML 元素简介
- 自定义Layout xml文件转换成View对象和Activity关联的实现
- Selenium & Nunit GUI & WebDriver
- 实现自定义窗口title
- 驱动函数poll 和 应用里的 select
- 在linux系统添加ip别名
- ios Xcode 安装 cocos2d-x 2.1.4
- VS 2005 处理条件
- Oracle数据库表被锁
- hdu2594(KMP)
- Android_UI_点击按钮切换背景效果实现
- IE快捷键使用