效果:

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();

    }

王立平--自己定义TitleBar的更多相关文章

  1. 王立平--TableLayout

    效果: <?xml version="1.0" encoding="utf-8"?>  <TableLayout xmlns:android= ...

  2. 王立平--android事件监听的3种方式

    第一种通常在activity组件的oncreate事件中直接定义,直接动作. 这样的方式每一个控件都定义一次.通常不方便. Button btn = (Button) findViewById(R.i ...

  3. 王立平--PopupWindow

    MainActivity.java <span style="font-size:14px;">package com.main; import android.app ...

  4. 王立平--string.Empty

    String.Empty 字段 .NET Framework 类库 表示空字符串.此字段为仅仅读.命名空间:System 程序集:mscorlib(在 mscorlib.dll 中) protecte ...

  5. 王立平--include在Android中的应用

    一个布局中包括还有一个布局 1.在layout下定义activity_other.xml布局 2.代码中的包括例如以下: <LinearLayout xmlns:android="ht ...

  6. 王立平--java se的简单项目创建以及具体解释

    创建项目的简单步骤: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzQyNTUyNw==/font/5a6L5L2T/fontsize/400/ ...

  7. 王立平--RemoteView

    RemoteView它将在两个地方被使用:一个是在AppWidget,另外一个是在Notification. RemoteView是用来描写叙述一个垮进程显示的view 1.AppWidget---R ...

  8. 王立平--EditPlus激活码

    注冊名:Free User 注冊码:6AC8D-784D8-DDZ95-B8W3A-45TFA

  9. 王立平-Android中对图像进行Base64编码

    // ------------------base64-------------------// public String bitmaptoString(Bitmap bitmap) { // 将B ...

随机推荐

  1. C#创建PDF文档

    说明:本实例用到了第三方组件ICSharpCode.SharpZipLib.dll.itextsharp.dll,该组件可到网上下载. 代码: using System; using System.C ...

  2. 2015.05.18,外语,学习笔记-《Word Power Made Easy》 03 “如何谈论不同从业者”

    Prefix Person,nous,etc. Practice,etc. Adjective psyche 精神 psychic ['saikik] adj.精神的n.灵媒 -logos 科研 ps ...

  3. lightshot截图工具的安装及使用

    通常我们做PPT或者写博客难免要用到截图工具,而Windows自带的snippingtool启动有延迟也不够方便,QQ有截屏又需要联网及登录情况下,于是我想着在Chrome上搜一款清新简洁的截屏软件, ...

  4. 关于懒加载中的self.和_

    ---恢复内容开始--- 在开发中,经常会用到懒加载,最常用的如加载一个数组 如图,在这个懒加载数组中有的地方用到了_array有的地方用到了self.array 原因是_array是直接访问,而se ...

  5. maven、spring jdbc与mysql、mybatis

    以它们之前的一个简单用例作为实例. 一个简单的能跑起来的实例.原文网址.非常好的例子. http://www.open-open.com/lib/view/open1390534380648.html ...

  6. spring《四》自动装配

    byName模式<bean autowire="byName"> Spring会查找一个叫做date的bean定义. byType模式<bean autowire ...

  7. SQL Server 查询所有包含某文本的存储过程、视图、函数

    •  方法一:查询所有包含某文本的存储过程.视图.函数 SELECT * from sysobjects o, syscomments s where o.id = s.id AND text LIK ...

  8. 以SqlHelper为例论面向对象中封装的使用

    引言: 在使用面向对象方法编写的程序中,会有一些工具类,如Utility,xxHelper等. 比如1)操作数据库的过程,一般步骤都是:1.准备数据库地址.表名等信息:2.建立连接:3.准备要执行sq ...

  9. 使用 Travis-CI 的五个理由

    I use the service of travis-ci now for a year. In that time the continuous integration has often poi ...

  10. IOS入门之创建视图和控件绑定

    学习IOS几天了,跟着教程做了两个小应用了,现在先来总结一下.今天就是创建视图和绑带到代码了.其实就是常见的MVC模式实现. 使用的Xcode版本是8.2. 在Xcode创建项目之后,默认就会创建一个 ...