一、先上个图吧,我程序上的截图
二、上程序
1、
// 设置窗口的布局
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);// 自定义标题
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);//自定义标题栏的xml文件
//从程序看放在主activity中,而且上面三步顺序不能随便写,就按上面顺就可以了。
下面来上R.layout.custom_title,,xml文件
<?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="fill_parent"
android:background="@drawable/share_custom_title"
>
<ImageView//这个控件我放那个黄色小图标的。
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="2dp"
android:background="@drawable/app_icon" >
</ImageView>
<TextView
android:id="@+id/title_left_text"
style="?android:attr/windowTitleStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="25dp"
android:layout_weight="1"
android:background="#00000000"
android:ellipsize="end"
android:singleLine="true" />
<TextView//这个就是中间那个显示温度的。
android:id="@+id/title_centre_text"
style="?android:attr/windowTitleStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="130dp"
android:layout_weight="1"
android:background="#00000000"
android:ellipsize="end"
android:singleLine="true" />
<TextView //这个就是用来显示连接状态的。
android:id="@+id/title_right_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:background="#00000000"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#ffffff"
android:layout_marginRight="2dp"
/>
</RelativeLayout>
// 设置自定义标题ID引用
TitleLeft = (TextView) findViewById(R.id.title_left_text);
TitleLeft.setText(R.string.app_name);
TitleCentre = (TextView) findViewById(R.id.title_centre_text);
TitleRight = (TextView) findViewById(R.id.title_right_text);
结语:不知道忘掉什么没写没有,有了以上步骤就可以实现自定义标题了。
源码下载:http://www.yxwojia.com/sort-3105990-1.html