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
做什麼?
Thankyou,這工作完美無瑕。但是,您是否也可以解釋Google如何做到這一點?只是好奇。我發現他們的操作欄佈局不具有預定義的整個佈局。 – 2011-05-31 05:55:43
嗨,你知道他們做到了嗎?我有同樣的問題。我用TextView試了一下,它的風格也不像樣。 – Bhiefer 2011-12-01 14:01:41