这篇文章给大家介绍如何在Android项目中自定义title,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。首先编写title的布局文件,title.xml:<?xml version="1.0
这篇文章给大家介绍如何在Android项目中自定义title,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
首先编写title的布局文件,title.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="Http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/bg_title"android:gravity="center_vertical"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/title_loGo"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/app_name"android:textSize="20sp"android:layout_marginLeft="80dip"android:textColor="#ffffff"/></LinearLayout>
然后在Activity的onCreate()里加上这三句话:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);setContentView(R.layout.main);getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);
需要注意的是这三句话的顺序不能变。到这里只是改变了title的布局,下面改变背景和高度,这就需要改变Activity的theme。
在values文件夹下新建文件style.xml:
<?xml version="1.0" encoding="utf-8"?><resources><style name="CustomWindowTitleBackground"><item name="android:background">@drawable/bg_title</item></style><style name="title_style" parent="android:Theme"><item name="android:windowTitleSize">44dip</item><item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item></style></resources>
最后在AndroidManifest.xml里面加上:
<activity android:name=".sysinfo"android:label="@string/app_name"android:screenOrientation="portrait"android:theme="@style/title_style">
关于如何在Android项目中自定义title就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
--结束END--
本文标题: 如何在Android项目中自定义title
本文链接: https://www.lsjlt.com/news/224924.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-06
2024-05-06
2024-05-06
2024-05-06
2024-05-06
2024-05-06
2024-05-06
2024-05-06
2024-05-06
2024-05-06
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0