title布局activity_main_title.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@color/title_background"
android:orientation="vertical" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="@drawable/icon" />
<TextView
android:id="@+id/icon_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_name"
android:layout_toRightOf="@id/icon"
android:textSize="18sp"/>
<ImageView
android:id="@+id/applist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:onClick="show_applist"
android:src="@drawable/titlebar_applist_normal" />
<ImageView
android:id="@+id/searchbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/applist"
android:onClick="search_app"
android:src="@drawable/titlebar_search_normal" />
</RelativeLayout>
关键代码:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.activity_main_title);
留白问题:
http://www.cnblogs.com/qingblog/archive/2012/09/03/2668542.html
其中
<resources>
<style name="StatusBarBackground">
<item name="android:background">@drawable/shape</item>
</style>
<style name="XWindowTitle" parent="android:WindowTitle">
<item name="android:shadowColor">#BB000000</item>
<item name="android:shadowRadius">0</item>
</style>
</resources>
在2.2后的版本 改为
</style>
<style name="StatusBarBackground"></style>
<style name="XWindowTitle" parent="android:TextAppearance.WindowTitle">
<item name="android:shadowColor">#BB000000</item>
<item name="android:shadowRadius">0</item>
</style>
总结:
有没有好用的部落格网站推荐下,某些网站实在太难用了,可惜没有找到好的替代品。。。