Android自定义标题栏
来源:互联网 发布:淘宝店铺转让协议 编辑:程序博客网 时间:2024/06/05 10:47
修改了标题栏布局,效果如下:
说一下具体步骤。首先,修改标题栏的宽度和背景,在strings.xml中添加:
<style name="CustomWindowTitleBackground">
<item name="android:background">@drawable/title_bg</item>
</style><style name="test" parent="android:Theme">
<item name="android:windowTitleSize">40dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
然后修改AndroidMainfest.xml文件:
<activity android:name=".MainActivity"
android:theme="@style/test">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
红色部分为加载Activity的theme。
接着修改MainActivity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//自定义布局赋值
}
注意红色部分标记的3行代码,顺序不能颠倒。
最后在layout文件夹中添加title.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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_centerVertical=’true’
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_email" />
<TextView android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:text="自定义标题栏" /></RelativeLayout>
原文:http://bigcat.easymorse.com/?p=840
- android自定义标题栏progressBar
- Android自定义标题栏
- 自定义android标题栏
- android实现自定义标题栏
- Android自定义标题栏
- Android 自定义标题栏
- Android 自定义标题栏
- Android自定义标题栏
- Android自定义标题栏
- android之自定义标题栏
- Android自定义标题栏
- Android 自定义标题栏运用
- Android 自定义标题栏
- android ListView+自定义标题栏
- Android 自定义标题栏
- Android:自定义标题栏
- Android Actionbar自定义标题栏
- 自定义Android标题栏TitleBar
- java堆内存与栈内存区别
- final类
- oracle查看表空间
- js求时间差
- appcan与iscroll.js结合下拉刷新(转)
- Android自定义标题栏
- Android之Adapter用法总结
- Android之自定义Adapter的ListView
- Android布局琐碎(原)
- Android去掉自动焦点
- 使用 CEvent 类
- 企业级Android安全退出
- Android Activity 生命周期
- Android判断APP是否第一次启动