---
title: "android之自定义带图片的title"
author: "yulon"
date: "2011-05-02T19:35:33Z"
tags: ["Android", "XML"]
categories: ["移动开发"]
slug: "android-title"
draft: false
lastmod: "2011-05-02T19:35:33Z"
id: 1026387
url: "https://yulon.iteye.com/blog/1026387"
---

1、title布局文件如下：

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    	<ImageView
    		android:layout_width="18px"
    		android:layout_height="18px"
    		android:src="@drawable/logo"
    	></ImageView>
    	<TextView
    		android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:textColor="#000"
    		android:textSize="14px"
    		android:text="@string/app_name"
    	></TextView>
</LinearLayout>
```

 

这是一个水平的LinearLayout布局，里面包含一个ImageView(显示图片)和一个TextView(显示文本).

 

2、LonginActivity实现类如下：

```
public class LoginActivity extends BaseActivity{

	 private  static String TAG="LoginActivity";
	 @Override
	 public void onCreate(Bundle savedInstanceState) {
		   super.onCreate(savedInstanceState);
		   requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		   setContentView(R.layout.login);    
		   getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,      
			          R.layout.title);   
	 }
	 
}
```

 BaseActivity是自己写的一个基类。

3、显示效果如下：  
![](http://dl.iteye.com/upload/attachment/473989/1fc895e9-437c-3683-afa2-1b803302ab8b.jpg)