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

首頁 > 系統 > Android > 正文

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

2019-10-23 18:35:38
字體:
來源:轉載
供稿:網友

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

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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿拉善右旗| 罗定市| 黑山县| 西藏| 安岳县| 盐山县| 富裕县| 威远县| 佛学| 榆树市| 房产| 酉阳| 祁连县| 昭通市| 德州市| 林甸县| 托里县| 商城县| 清徐县| 西乡县| 明水县| 高阳县| 金平| 庐江县| 德州市| 萝北县| 逊克县| 瑞丽市| 东乡族自治县| 赤水市| 贵州省| 龙门县| 商水县| 奎屯市| 巴青县| 若羌县| 岢岚县| 兴化市| 乐平市| 镇巴县| 璧山县|