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 values, values-v11, and values-14 folders.
I have an activity that I would like to use the ?android:attr/buttonBarStyle and ?android:attr/buttonBarButtonStyle styles but I am unsure how to fall back to a different style when they are not available (such as @android:style/ButtonBar). Here is my layout for reference.
<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" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button One" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button Two" />
</LinearLayout>
I solved this by using two separate layout files, one located in the
layoutfolder and one located inlayout-v11. They are almost the same except that they contain different values for thestyleattribute.The first one looks like this (in
layout):The second one looks like this (in
layout-v11):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/buttonBarButtonStyleas a parent style, but I couldn’t find a way to accomplish this.