中文字幕第五页-中文字幕第页-中文字幕韩国-中文字幕最新-国产尤物二区三区在线观看-国产尤物福利视频一区二区

Android開發如何在4.0及以上系統中自定義TitleBar-創新互聯

本文將通過一個實例講解怎么實現在4.0及以上系統版本中實現自定義TitleBar,這只是我自己找到的一種方法;Android開發如何在4.0及
以上系統中自定義TitleBar

xml布局文件

專注于為中小企業提供成都網站設計、成都網站制作、外貿網站建設服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業威遠免費做網站提供優質的服務。我們立足成都,凝聚了一批互聯網行業人才,有力地推動了成百上千企業的穩健成長,幫助中小企業通過網站建設實現規模擴充和轉變。

activity_main.xml

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:paddingBottom="@dimen/activity_vertical_margin"
  6. android:paddingLeft="@dimen/activity_horizontal_margin"
  7. android:paddingRight="@dimen/activity_horizontal_margin"
  8. android:paddingTop="@dimen/activity_vertical_margin"
  9. tools:context=".MainActivity" >
  10. <TextView
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:text="@string/hello_world" />
  14. </RelativeLayout>

自定義的Titlebar的布局文件titlebar.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="48dp"
  5. android:orientation="horizontal" >
  6. <ImageView
  7. android:layout_width="wrap_content"
  8. android:layout_height="wrap_content"
  9. android:layout_gravity="center"
  10. android:layout_weight="1.5"
  11. android:src="@drawable/ic_action_search" />
  12. <TextView
  13. android:layout_width="wrap_content"
  14. android:layout_height="48dp"
  15. android:layout_weight="1.5"
  16. android:paddingTop="1dp"
  17. android:text="@string/app_name"
  18. android:textSize="14sp" />
  19. <EditText
  20. android:id="@+id/searchparameter"
  21. android:layout_width="wrap_content"
  22. android:layout_height="48dp"
  23. android:layout_margin="1dp"
  24. android:layout_weight="5"
  25. android:text="ABCDEFGHIJ"
  26. android:textSize="14sp" />
  27. <Button
  28. android:id="@+id/button"
  29. android:layout_width="wrap_content"
  30. android:layout_height="48dp"
  31. android:layout_margin="1dp"
  32. android:layout_weight="2"
  33. android:text="OK"
  34. android:textSize="14sp" />
  35. </LinearLayout>

為布局文件修改style.xml

此處的style.xml在values-11或者value-14中,否側會報錯:you cannot combine custom titles with other title features

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources xmlns:android="http://schemas.android.com/apk/res/android">
  3. <style name="CustomizedWindowTitleBackground">
  4. <item name="android:background">#047BF0</item>
  5. </style>
  6. <style name="titlebarstyle" parent="android:Theme">
  7. <item name="android:windowTitleSize">48dp</item>
  8. <item name="android:windowTitleBackgroundStyle">@style/CustomizedWindowTitleBackground</item>
  9. <!-- All customizations that are NOT specific to a particular API-level can go here. -->
  10. </style>
  11. </resources>

在AndroidManifest.xml添加主題樣式

android:theme="@style/titlebarstyle"

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.example.titlebardemo"
  4. android:versionCode="1"
  5. android:versionName="1.0" >
  6. <uses-sdk
  7. android:minSdkVersion="8"
  8. android:targetSdkVersion="17" />
  9. <application
  10. android:allowBackup="true"
  11. android:icon="@drawable/ic_launcher"
  12. android:label="@string/app_name" >
  13. <activity
  14. android:name="com.example.titlebardemo.MainActivity"
  15. android:label="@string/app_name"
  16. android:theme="@style/titlebarstyle" >
  17. <intent-filter>
  18. <action android:name="android.intent.action.MAIN" />
  19. <category android:name="android.intent.category.LAUNCHER" />
  20. </intent-filter>
  21. </activity>
  22. </application>
  23. </manifest>

MainActivity.java中添加實現代碼

  1. protected void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
  4. setContentView(R.layout.activity_main);
  5. getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
  6. R.layout.titlebar);
  7. }

代碼中requestWindowFeature(Window.FEATURECUSTOMTITLE);和getWindow().setFeatureInt(Window.FEATURECUSTOMTITLE, R.layout.titlebar);位置是固定的.

希望讀者朋友們通過這個例子能夠對怎么實現在4.0及以上系統版本中自定義TitleBar有深刻理解和掌握。

本文標題:Android開發如何在4.0及以上系統中自定義TitleBar-創新互聯
鏈接URL:http://m.2m8n56k.cn/article16/dipcdg.html

成都網站建設公司_創新互聯,為您提供網站排名外貿建站面包屑導航服務器托管標簽優化App設計

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都app開發公司
主站蜘蛛池模板: 日日摸夜夜搂人人要 | 国产91丝袜美腿在线观看 | 综合欧美日韩一区二区三区 | 亚洲国产综合精品 | 国产精品福利视频萌白酱 | 性欧美在线 | 欧美一区二区三区免费 | 国产精品久久国产三级国不卡顿 | 一区二区伦理 | 国产人做人爱免费视频 | 免费播放欧美毛片欧美a | 免费人成激情视频在线观看冫 | 99re免费99re在线视频手机版 | 欧美特黄特色aaa大片免费看 | 成人做爰网站免费看 | 三级网站国产 | 欧美巨大精品欧美一区二区 | 国产午夜免费视频片夜色 | 精品久久久久国产免费 | 在线免费视频 | 亚洲精品视频免费观看 | 亚洲综合视频网 | 久久999精品 | 国产在线观看免费视频软件 | 久久性妇女精品免费 | 国产成人精品亚洲一区 | 97se狠狠狠狠狠亚洲综合网 | 日韩精品免费一级视频 | 九九久久视频 | 色偷偷在线刺激免费视频 | 亚洲欧美偷拍自拍 | 国产精品福利视频萌白酱 | 沈樵在线观看福利 | 国产a级高清版毛片 | 久久久久久久久网站 | 亚洲人成综合在线播放 | 亚洲高清国产拍精品影院 | 国内精品免费一区二区三区 | 国产区一区二区三区 | 国产亚洲人成在线影院 | 12345国产精品高清在线 |