更新时间:2023-12-04 21:49:58
我通过位于两个不同的布局文件,一个位于布局
文件夹,一个解决了这个布局-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中>
我不完全满意,这种方法的,因为重复的信息量。我想找到一种方法,使用安卓?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.