国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android編程實現自定義title功能示例

2019-12-12 03:28:53
字體:
來源:轉載
供稿:網友

本文實例講述了Android編程實現自定義title功能。分享給大家供大家參考,具體如下:

這里我在前面加了個logo,而且改變了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">

這樣就實現了自定義title。

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android開發入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 卢龙县| 西林县| 保山市| 广饶县| 罗平县| 平邑县| 东方市| 建阳市| 沙田区| 鄂州市| 泸定县| 无为县| 中西区| 津南区| 定州市| 栾川县| 蓬溪县| 丰顺县| 昭觉县| 龙山县| 姜堰市| 丰镇市| 沽源县| 句容市| 来宾市| 兴城市| 六盘水市| 垦利县| 信宜市| 临夏市| 卢氏县| 和平县| 山西省| 永城市| 安顺市| 怀安县| 抚松县| 肃宁县| 舞阳县| 剑阁县| 曲阜市|