日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android開發(fā)如何在4.0及以上系統(tǒng)中自定義TitleBar

本文將通過一個實例講解怎么實現(xiàn)在4.0及以上系統(tǒng)版本中實現(xiàn)自定義TitleBar,這只是我自己找到的一種方法;

xml布局文件

activity_main.xml

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

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

 
 
  1.  
  2.     android:layout_width="match_parent" 
  3.     android:layout_height="48dp" 
  4.     android:orientation="horizontal" > 
  5.     
  6.         android:layout_width="wrap_content" 
  7.         android:layout_height="wrap_content" 
  8.         android:layout_gravity="center" 
  9.         android:layout_weight="1.5" 
  10.         android:src="@drawable/ic_action_search" /> 
  11.     
  12.         android:layout_width="wrap_content" 
  13.         android:layout_height="48dp" 
  14.         android:layout_weight="1.5" 
  15.         android:paddingTop="1dp" 
  16.         android:text="@string/app_name" 
  17.         android:textSize="14sp" /> 
  18.     
  19.         android:id="@+id/searchparameter" 
  20.         android:layout_width="wrap_content" 
  21.         android:layout_height="48dp" 
  22.         android:layout_margin="1dp" 
  23.         android:layout_weight="5" 
  24.         android:text="ABCDEFGHIJ" 
  25.         android:textSize="14sp" /> 
  26.     
  27.         android:id="@+id/button" 
  28.         android:layout_width="wrap_content" 
  29.         android:layout_height="48dp" 
  30.         android:layout_margin="1dp" 
  31.         android:layout_weight="2" 
  32.         android:text="OK" 
  33.         android:textSize="14sp" /> 
  34.  

為布局文件修改style.xml

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

 
 
  1.  
  2.  
  3.      
  4.         #047BF0 
  5.      
  6.      
  7.         48dp 
  8.         @style/CustomizedWindowTitleBackground 
  9.          
  10.      
  11.  

在AndroidManifest.xml添加主題樣式

android:theme="@style/titlebarstyle"

 
 
  1.  
  2.     package="com.example.titlebardemo" 
  3.     android:versionCode="1" 
  4.     android:versionName="1.0" > 
  5.     
  6.         android:minSdkVersion="8" 
  7.         android:targetSdkVersion="17" /> 
  8.     
  9.         android:allowBackup="true" 
  10.         android:icon="@drawable/ic_launcher" 
  11.         android:label="@string/app_name" > 
  12.         
  13.             android:name="com.example.titlebardemo.MainActivity" 
  14.             android:label="@string/app_name" 
  15.            android:theme="@style/titlebarstyle" > 
  16.              
  17.                  
  18.                  
  19.              
  20.          
  21.      
  22.  

MainActivity.java中添加實現(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);位置是固定的.

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


網(wǎng)站欄目:Android開發(fā)如何在4.0及以上系統(tǒng)中自定義TitleBar
文章路徑:http://m.5511xx.com/article/dhgdjhc.html