定制化 标题
[功能]
默认标题仅支持文字 通过定制化 可以支持图片
[代码 步骤]
1. 定义其所需的布局:title.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="fill_parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/robot"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="HelloTitle!"
/>
</LinearLayout>
2. 如何使用:
public class HelloTitle extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
}
}
3. tha's all! emulator 运行截图: