Android Button Bar in Holo

后端 未结 2 1050
感动是毒
感动是毒 2021-02-06 20:03

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

相关标签:
2条回答
  • 2021-02-06 20:38

    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>
    
    0 讨论(0)
  • 2021-02-06 20:42

    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.

    0 讨论(0)
提交回复
热议问题