I am creating an Android app that uses the Holo theme when available and falls back to the black theme when it isn\'t available. I am accomplishing this by using the value
Well, I'm a little bit late, but this is how I solved it:
<LinearLayout
android:id="@+id/footer"
style="@style/ButtonBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/accountSpinner"
android:orientation="horizontal" >
<Button
android:id="@android:id/button1"
style="@style/ButtonBarButton"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:text="@string/login" />
<Button
android:id="@android:id/button2"
style="@style/ButtonBarButton"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:enabled="false"
android:text="@string/login" />
</LinearLayout>
with this styles:
<style name="ButtonBarButton">
</style>
<style name="ButtonBar" parent="@android:style/ButtonBar">
</style>
and for v11:
<style name="ButtonBarButton" parent="@android:style/Widget.Holo.Button.Borderless">
<item name="android:textColor">@android:color/primary_text_light</item>
</style>
<style name="ButtonBar" parent="@android:style/Holo.Light.ButtonBar.AlertDialog">
</style>
I solved this by using two separate layout files, one located in the layout
folder and one located in layout-v11
. They are almost the same except that they contain different values for the style
attribute.
The first one looks like this (in layout
):
<LinearLayout
android:id="@+id/buttonArea"
style="@style/buttonBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom|right"
android:orientation="horizontal"
android:padding="5dp" >
<Button
android:id="@+id/button1"
style="@style/buttonBarButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/button2"
style="@style/buttonBarButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
The second one looks like this (in layout-v11
):
<LinearLayout
android:id="@+id/buttonArea"
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom|right"
android:orientation="horizontal"
android:padding="5dp" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/button2"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
I am not completely satisfied with this approach because of the amount of duplicate information. I would like to find a way to use ?android:attr/buttonBarButtonStyle
as a parent style, but I couldn't find a way to accomplish this.