日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

android分享的主标题,Android 自定义标题栏(title栏)

發布時間:2025/3/19 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android分享的主标题,Android 自定义标题栏(title栏) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

近日

需要在android的標題欄上添加按鈕,所以對android的標題欄進行了一下簡單的研究~

第一步,向實現自定義標題欄,需要在onCreate方法里這樣寫

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,?R.layout.title_bar);

注意:

requestWindowFeature要在setContentView之前

getWindow().setFeatureInit最好在setContentView之后

第二步,就是寫好自己的布局文件,實現標題欄的自定義。

不過我們會遇到一些問題,就是標題欄的高度不能自定義~下面就是解決辦法~

下面,我們看一下android title標題欄 在源碼 framework中的XML文件

screen_custom_title.xml

android:layout_width="match_parent"

android:layout_height="?android:attr/windowTitleSize"

style="?android:attr/windowTitleBackgroundStyle">

android:layout_width="match_parent"

android:layout_height="0dip"

android:layout_weight="1"

android:foregroundGravity="fill_horizontal|top"

android:foreground="?android:attr/windowContentOverlay"/>

screen_title.xml

android:layout_height="?android:attr/windowTitleSize"

style="?android:attr/windowTitleBackgroundStyle">

style="?android:attr/windowTitleStyle"

android:background="@null"

android:fadingEdge="horizontal"

android:gravity="center_vertical"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

android:layout_width="match_parent"

android:layout_height="0dip"

android:layout_weight="1"

android:foregroundGravity="fill_horizontal|top"

android:foreground="?android:attr/windowContentOverlay"/>

既然是自定義標題,那我們就看screen_custom_title.xml,里面有一個title_container和一個content,組合成了標題欄,我們自定義標題所給出的view,都被content作為子view了,影響不了那個title_container和content,所以,任你怎么弄,它該留白的還是留白,你沒招。

看title_container有個style是這樣的:

style="?android:attr/windowTitleBackgroundStyle"

content的foreground是這樣的android:foreground="?android:attr/windowContentOverlay"

我們可以自己寫一個style

#00cc00

50dp

@style/CustomWindowTitleBackground

加入到AndroidManifest

android:label="@string/app_name"android:theme="@style/title_bar">

PS:做的略顯粗糙,不過以能實現功能為主~~

總結

以上是生活随笔為你收集整理的android分享的主标题,Android 自定义标题栏(title栏)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。