如何定制Activity的标题栏
2024-10-13 17:22:50
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
//自定义标题栏
mWindow = getWindow();
mWindow.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar);
titlebar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:text="@string/app_name"
android:textColor="#000"
android:paddingRight="3.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="@string/battery_text"
android:textColor="#000"
android:paddingRight="3.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/battery_text"
android:textColor="#00f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
上述的话只是适合android4.0一下的版本,如果需要针对android4.0以上的版本的话需要我们使用自己的样式
<style name="TitleBackgroundColor">
<item name="android:background">@color/background_color</item>
</style> <style name="titlestyle" parent="android:Theme" >
<item name="android:windowTitleSize">40dip</item>
<item name="android:windowTitleBackgroundStyle">@style/TitleBackgroundColor</item>
</style>
然后在配置文件中加上,OK
<activity android:name="com.ygl.ui.LoginActivity"
android:theme="@style/titlestyle" ></activity>
最新文章
- appium 环境搭建 java
- 一起学HTML基础-格式与布局fixed/absolute/relative/z-index/float
- 【iCore3 双核心板】例程二十:LAN_TCPC实验——以太网数据传输
- asp接收jquery post 中文乱码问题!
- Unity Scripting Tutorials 要点记录
- Fatjar成功安装记录
- 使用Calendar获取近三年的财务信息
- 关于std::string
- poj3414(bfs)
- Vim快捷键大全
- 身为运维的你,怎么掌握python才不会失业
- javascript实现继承3种方式: 原型继承、借用构造函数继承、组合继承,模拟extends方法继承
- AllocateHWnd SetTimer API
- 基于Manhattan最小生成树的莫队算法
- Container Adaptors
- Python学习笔记——Python Number(数字)
- 牛客网-《剑指offer》-调整数组顺序使奇数位于偶数前面
- oracle dblink 查询 tns:无法解析指定的连接标识符
- curl 一个无比有用的网站开发工具
- 腾讯云-搭建 WordPress 个人博客