Android编程实现自定义title功能示例
2019/7/7 20:50:18
本文主要是介绍Android编程实现自定义title功能示例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本文实例讲述了Android编程实现自定义title功能。分享给大家供大家参考,具体如下:
这里我在前面加了个logo,而且改变了title的背景和高度。
首先编写title的布局文件,title.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns: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"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/title_logo" /> <TextView android: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" >
这样就实现了自定义title。
更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android多媒体操作技巧汇总(音频,视频,录音等)》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。
这篇关于Android编程实现自定义title功能示例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-18android.permission.read_media_video
- 2024-01-18android_getaddrinfo failed eai_nodata
- 2024-01-18androidmo
- 2024-01-15Android下三种离屏渲染技术
- 2024-01-09Android 蓝牙使用
- 2024-01-06Android对接华为AI - 文本识别
- 2023-11-15代码安全之代码混淆及加固(Android)
- 2023-11-10简述Android语音播报TTS
- 2023-11-06Android WiFi工具类
- 2023-07-22Android开发未来的出路