王立平--自己定义TitleBar
效果:
1.自己定义titleBar的布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tv_SongsCount"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:singleLine="true"
android:text="2222"
android:textColor="#FFFFF0"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:text="hahahahaha"
android:textColor="#3a3a3a"
android:textSize="20sp" />
<ImageButton
android:id="@+id/imgBtn_ToPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="@null"
android:contentDescription="ppppme"
android:src="@drawable/btn" />
</RelativeLayout>
2.在.java中载入布局。
private void initTitleBar() {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.titlebar);
}
3.调用initTitleBar
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//声明使用自己定义标题
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
initTitleBar();
}
最新文章
- 以冒泡排序为例--malloc/free 重定向stdin stdout
- Jetty使用教程(四:21-22)—Jetty开发指南
- 肯爹的 StringUtils.isNumeric(String str)
- C语言中的++和--
- CLRS:max_heap and min_heap operation (pseudocode)
- for循环绑定事件,闭包思想!
- AngularJS数据建模(转载)
- 设计理念 : popup login 在前后台
- 命令行创建Maven项目卡住以及出错解决办法。
- python语言基础语法笔记<;note2--面向对象编程>;
- .net core下用HttpClient和asp.net core实现https的双向认证
- idea的一般使用和初始配置
- IDEA 启动项目前的配置--或过程遇到的问题
- 分治法——快速排序(quicksort)
- LAB4
- iOS objc_msgSend 报错解决方案
- poj 1879 Truck History
- Azure Linux 虚拟机常见导致无法远程的操作
- php独特的语法
- atitit。获取表格的字段注释metadata的原理以及AND 字段表格描述文档方案