开发者

Android: Action bar for phones

I was trying to extract the action bar from the Google I/O 2011 app, but I cannot seem to figure out how they set the title and buttons on the bar. Basically I couldn't figure out how the <declare-stylable> worked.

So in the attr.xml, they have declared this

  <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="trackAbstractMaxLin开发者_开发知识库es" format="integer" />
</declare-styleable>

In 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>

And I guess I should be using this code to add the logo to the bar,

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

But nothing happens. I know I have missed out something while copy/pasting :D but I cannot figure out what!..

Also what is the use of declare-stylable an what does the format=reference do?


First, you might want to use something that is already a reusable component.

what is the use of declare-stylable

That is used by custom Views to declare custom attributes that you can supply in your layouts.

what does the format=reference do

That indicates that the custom attribute takes, as a value, a reference to a resource. In this case, it would appear to be references to style resources.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜