Android標題欄添加控件及Button控件背景顏色的設置_第1頁
Android標題欄添加控件及Button控件背景顏色的設置_第2頁
Android標題欄添加控件及Button控件背景顏色的設置_第3頁
Android標題欄添加控件及Button控件背景顏色的設置_第4頁
免費預覽已結束,剩余1頁可下載查看

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、Android標題欄添加控件及 Button控件背景顏色的設置、An droid中標題欄添加按現在很多的An droid程序都在標題欄上都顯示了一些按鈕和標題,如下圖:腸®崗屮Q O亨刑皿3個眈上一步選擇相片卡一步下面通過實例來看一下如何實現。1、在layout下創建一個titlebtn.xml文件,內容如下:<?xml version="1.0" encoding="utf-8" ?>vRelativeLayoutxm In s:a ndroid= " ndroid" an droid:layout_width

2、= "fill_pare nt"an droid:layout_height= "fill_pare nt"android:orientation= "horizontal" > vlmageButt onan droid:id= "+id/imageButto n1"an droid:layout_width= "wrap_c on te nt" an droid:layout_height= "wrap_c on te nt" an droid:layout_ali

3、g nPare ntLeft= "true" an droid:layout_ce nterVertical= "true" an droid:backgrou nd= "#00000000" android:src= "drawable/prv" /> <TextViewan droid:layout_width= "wrap_c on te nt" an droid:layout_height= "wrap_c on te nt" an droid:layou

4、t_ce nterl nPare nt= "true" an droid:text="標題欄"/> vlmageButt onan droid:id= "+id/imageButto n1"an droid:layout_width= "wrap_c on te nt" an droid:layout_height= "wrap_c on te nt"android:layout_alignParentRight= "true" android:layout_cente

5、rInParent= "true" android:background= "#00000000" android:src= "drawable/next" /></ RelativeLayout >在創建這個 xml 時需要 注意 :a)使用 RelativeLayout 的布局b)特別是右邊按鈕的屬性需要指定layout_ce nterl nPare nt從而有不同Button 控件背景顏色的設置 里我舉例如何使用selector,layer-list 完成 button 背景的層疊組合,情形下不同效果butto

6、n_ctrl.xml 中選擇器<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="<item android:state_pressed="true" android:drawable="drawable/button_highlight_ctrl" /><item android:drawable="drawable/button_normal_ctrl" /><

7、/selector>button_highlight_ctrl.xml 中兩層圖<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android=" <itemandroid:drawable="drawable/button_highlight_back"android:top="2dip"android:right="2dip"android:bottom="2dip"a

8、ndroid:left="2dip"/><item android:drawable="drawable/button_highlight_fore" android:top="2dip"android:right="2dip"android:bottom="2dip"android:left="2dip"/></layer-list>button_highlight_back.xml中完成背景顏色的漸變 <?xml version=&qu

9、ot;1.0" encoding="utf-8"?><shape xml ns:a ndroid=" ndroid"an droid:shape="recta ngle"><cor nersan droid:radius="4dip"/><gradie ntan droid:type="li near"an droid:a ngle="270"an droid:startColor="color/highlight_bu

10、tt on_ start_color"an droid:ce nterColor="color/highlight_butt on_ middle_color"an droid:e ndColor="color/highlight_butto n_en d_color"/></shape>button_highlight_fore是一張前景圖片,即按下時的頂部陰影:至此,已完成高亮butt on的制作,接下來是普通butt onbutton_ no rmal_ctrl.xml 中兩層圖<?xml version=&quo

11、t;1.0" encoding="utf-8"?><layer-list xml ns:a ndroid=" ndroid"><iteman droid:drawable="drawable/butt on_no rmal_back"an droid:top="2dip"an droid:right="2dip"an droid:bottom="2dip"an droid:left="2dip"/><iteman droid:drawable="drawable/butt on_no rmal_fore"an droid:top="2dip"an droid:right="2dip"an droid:bottom=

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論