I'm trying to style buttons to look like those I ask about in Android Full Width ICS style Minimalist Bottom ButtonsViews.
I've succeeded, with the following xml for anyone interested:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:divider="@android:drawable/divider_horizontal_dark"
android:gravity="bottom"
android:orientation="vertical"
android:paddingTop="16dip"
android:showDividers="beginning|end" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:measureWithLargestChild="true"
android:orientation="horizontal"
android:divider="@android:drawable/divider_horizontal_dark"
android:showDividers="middle" >
<Button
android:id="@+id/cancel_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:maxLines="2"
android:text="@string/cancel_button" />
<Button
android:id="@+id/login_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:filterTouchesWhenObscured="true"
android:maxLines="2"
android:text="@string/login_button" />
</LinearLayout>
</LinearLayout>
One question though. The eclipse content assist has no idea what's happening with the following resource resolution:
style="?android:attr/buttonBarButtonStyle"
I'm familiar with the typical resolution (which eclipse's content assist is aware of)
style=@android/style/...
...but I'm not clear on the difference between the two. It seems like some style attributes appear in one but not the other. For instance, the following doesn't resolve to anything:
style=@android:attr/buttonBarStyle
and neither does this:
style="@android:style/buttonBarStyle
So I guess two questions here:
Thanks!
A style is a collection of attributes that specify the appearance for a single View . A style can specify attributes such as font color, font size, background color, and much more. A theme is a collection of attributes that's applied to an entire app, activity, or view hierarchy—not just an individual view.
The Attr interface represents an attribute in an Element object. Typically the allowable values for the attribute are defined in a schema associated with the document.
A style is defined in an XML resource that is separate from the XML that specifies the layout. This XML file resides under res/values/ directory of your project and will have <resources> as the root node which is mandatory for the style file. The name of the XML file is arbitrary, but it must use the . xml extension.
Note: A style is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine style resources with other simple resources in the one XML file, under one <resources> element. The filename is arbitrary.
From another answer on SO (paraphrased here):
Using a question mark in front of an ID means that you want to access a style attribute that's defined in a style theme, rather than hardcoding the attribute.
Think of it as dereferencing a theme attribute to fetch the resource it points to rather than referring to the attribute itself.
Referencing Style Attributes
?android:attr/buttonBarButtonStyle or just ?android:buttonBarButtonStyle - (attr is optional)
<item name="buttonBarButtonStyle">@android:style/Widget.Button</item>
This internally dereferences to @android:style/Widget.Button which is defined within appcompat/res/values/themes.xml file.
(?android:) - always links to the value of the attribute from the current-theme applied. Thus allowing us to refer the android defined style only rather creating a new one and supplying a hard-coded value.
Google Doc says, "It uses the style that is defined by this attribute, in the current theme"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With