bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

Android開(kāi)發(fā)如何在4.0及以上系統(tǒng)中自定義TitleBar-創(chuàng)新互聯(lián)

本文將通過(guò)一個(gè)實(shí)例講解怎么實(shí)現(xiàn)在4.0及以上系統(tǒng)版本中實(shí)現(xiàn)自定義TitleBar,這只是我自己找到的一種方法;Android開(kāi)發(fā)如何在4.0及
以上系統(tǒng)中自定義TitleBar

xml布局文件

專(zhuān)注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)威遠(yuǎn)免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了成百上千企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

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中,否側(cè)會(huì)報(bào)錯(cuò):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>

在A(yíng)ndroidManifest.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中添加實(shí)現(xiàn)代碼

  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);位置是固定的.

希望讀者朋友們通過(guò)這個(gè)例子能夠?qū)υ趺磳?shí)現(xiàn)在4.0及以上系統(tǒng)版本中自定義TitleBar有深刻理解和掌握。

本文標(biāo)題:Android開(kāi)發(fā)如何在4.0及以上系統(tǒng)中自定義TitleBar-創(chuàng)新互聯(lián)
鏈接URL:http://vcdvsql.cn/article16/dipcdg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名外貿(mào)建站面包屑導(dǎo)航服務(wù)器托管標(biāo)簽優(yōu)化App設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開(kāi)發(fā)公司