android 自定标题栏的应用
2015-06-13 03:00
501 查看
一、先上个图吧,我程序上的截图
二、上程序
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
二、上程序
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
相关文章推荐
- 安卓自定义标题
- Android 自定义标题栏 TitleBar
- windows下tomcat指定命令窗口标题
- DialogFragment自定义标题及其点击事件
- iOS中UIAlertController设置自定义标题与内容的方法
- android 把1位数,补0变成2位数
- android 获取手机内存大小
- android 缓存读取与清除
- Android 使用Fiddler对应用进行抓包(一)
- android List,HashMap,Iterator
- Android事件传递机制
- Android 真机连接本地PC服务器
- Android ToolBar 的简单封装
- Android 学习 5 ->用代码布局和xml布局
- Android天气预报小项目的一些总结
- Android 获取内外置存储卡方法
- Android4.4——InputManagerService之InputReader线程
- Android调用系统相机和自定义相机实例
- 百度地图(一)AK申请与给应用签名
- android sdk更新下载失败问题