在全息Android的按钮栏全息、按钮、Android

2023-09-05 01:37:09 作者:你的温柔只许我拥抱

我创建一个Android应用程序,使用了全息主题可用时,将回退到黑色主题时,它不可用。我使用值实现此值-V11 值-14 文件夹。

我有,我想使用 Android的一个活动:ATTR / buttonBarStyle 安卓?ATTR / buttonBarButtonStyle 的风格,但我不能确定如何回落到一个不同的风格的时候都没有用(如 @android:款式/按钮栏)。这是我的布局,以供参考。

 <的LinearLayout
    机器人:ID =@ + ID / buttonArea
    风格=机器人:ATTR / buttonBarStyle
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:重力=底部|右
    机器人:方向=横向>

    <按钮
        机器人:ID =@ + ID /按钮1
        风格=机器人:ATTR / buttonBarButtonStyle
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:文本=按钮,一个/>

    <按钮
        机器人:ID =@ + ID /按钮2
        风格=机器人:ATTR / buttonBarButtonStyle
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:文本=两个按钮/>
< / LinearLayout中>
 

解决方案

我通过位于两个不同的布局文件,一个位于布局文件夹,一个解决了这个布局-V11 。他们几乎除了它们包含的不同值风格属性相同。

第一个看起来像这样(在布局):

 <的LinearLayout
    机器人:ID =@ + ID / buttonArea
    风格=@风格/按钮栏
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:重力=底部|右
    机器人:方向=横向
    机器人:填充=5DP>

    <按钮
        机器人:ID =@ + ID /按钮1
        风格=@风格/ buttonBarButton
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1/>

    <按钮
        机器人:ID =@ + ID /按钮2
        风格=@风格/ buttonBarButton
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1/>
< / LinearLayout中>
 

第二个看起来像这样(在布局-V11 ):

 <的LinearLayout
    机器人:ID =@ + ID / buttonArea
    风格=机器人:ATTR / buttonBarStyle
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:重力=底部|右
    机器人:方向=横向
    机器人:填充=5DP>

    <按钮
        机器人:ID =@ + ID /按钮1
        风格=机器人:ATTR / buttonBarButtonStyle
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1/>

    <按钮
        机器人:ID =@ + ID /按钮2
        风格=机器人:ATTR / buttonBarButtonStyle
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1/>
< / LinearLayout中>
 
色彩的变幻 历代Android界面的演变史

我不完全满意,这种方法的,因为重复的信息量。我想找到一种方法,使用安卓?ATTR / buttonBarButtonStyle 作为父母的风格,但我无法找到一个方法来做到这一点。

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