2011-05-30 102 views
1

我試圖從Google I/O 2011 app中提取操作欄,但我似乎無法弄清楚他們如何在欄上設置標題和按鈕。基本上我無法弄清楚<declare-stylable>是如何工作的。Android:手機操作欄

所以在attr.xml,他們宣稱這

<declare-styleable name="AppTheme"> 
    <attr name="actionbarButtonStyle" format="reference" /> 
    <attr name="actionbarProgressIndicatorStyle" format="reference" /> 
    <attr name="actionbarSeparatorStyle" format="reference" /> 
    <attr name="actionbarLogoStyle" format="reference" /> 
    <attr name="actionbarTextStyle" format="reference" /> 
    <attr name="textHeaderMaxLines" format="integer" /> 
    <attr name="trackAbstractMaxLines" format="integer" /> 
</declare-styleable> 

styles.xml

<style name="ActionBarLogo"> 
    <item name="android:id">@id/actionbar_logo</item> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">fill_parent</item> 
    <item name="android:clickable">false</item> 
    <item name="android:scaleType">center</item> 
    <item name="android:contentDescription">Logo</item> 
    <item name="android:src">@drawable/actionbar_logo</item> 
</style> 

而且我想我應該可以使用此代碼來標識添加到酒吧,

ImageButton logo = new ImageButton(mActivity, null, R.attr.actionbarLogoStyle); 
logo.setOnClickListener(homeClickListener); 
actionBarCompat.addView(logo); 

但沒有任何反應。我知道我錯過了一些東西,而複製/粘貼:D,但我無法弄清楚什麼!

declare-stylable什麼是format=reference做什麼?

回答

0

首先,您可能需要使用something that is already a reusable component

什麼是所使用的自定義視圖聲明自定義的使用聲明,風格化的

的屬性,你可以在你的佈局提供。

什麼是格式=基準做

這表示自定義屬性的重視,作爲一種價值,對資源的引用。在這種情況下,它似乎是對樣式資源的引用。

+0

Thankyou,這工作完美無瑕。但是,您是否也可以解釋Google如何做到這一點?只是好奇。我發現他們的操作欄佈局不具有預定義的整個佈局。 – 2011-05-31 05:55:43

+0

嗨,你知道他們做到了嗎?我有同樣的問題。我用TextView試了一下,它的風格也不像樣。 – Bhiefer 2011-12-01 14:01:41