以下三句代码放到oncreat中即可
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);
注意3句代码的顺序
主要思想是通过一个XML实现对titile栏的位置控制
title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="center">
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textTitle" />
</LinearLayout>
本文介绍如何使用三行代码在Android应用中自定义标题栏,并提供了具体的XML布局文件示例,便于开发者快速实现个性化的标题栏设计。
1万+

被折叠的 条评论
为什么被折叠?



