【问题标题】:buttonBarStyle requires API level 11buttonBarStyle 需要 API 级别 11
【发布时间】:2014-07-03 20:37:19
【问题描述】:

我正在尝试这个:

<RelativeLayout
    android:id="@+id/alert_banner"
    style="?android:attr/buttonBarStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_marginBottom="2dip"
    android:background="@color/holo_red_light"
    android:orientation="horizontal"
    android:padding="1dip" >

    <Button
        android:id="@+id/alert_banner_button"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:textColor="#EEEEEE" 
        android:text="@string/offline_warning_text"/>

</RelativeLayout>

样式线给了我这个错误:

?android:attr/buttonBarStyle 需要 API 级别 11(当前最小值为 10)

不知道为什么,我正在使用 app compat lib。我可以使用应用兼容样式吗?

【问题讨论】:

    标签: android android-layout android-menu android-appcompat


    【解决方案1】:

    你可以找到完整的实现here

    将此用于 API10:

    <!--
      A button bar is a set of buttons at the bottom of an activity.
      An example is an AlertDialog with OK/Cancel buttons.
    
      Note that something similar can be accomplished using a
      split action bar and text-only action buttons, but this is an
      alternate presentation that's often preferred.
    -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="?android:attr/listDivider"
        android:orientation="vertical"
        android:showDividers="middle" >
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Hello World" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:divider="?android:attr/listDivider"
            android:dividerPadding="12dp"
            android:orientation="horizontal"
            android:showDividers="middle" >
    
            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@android:drawable/list_selector_background"
                android:paddingLeft="4dp"
                android:paddingRight="4dp"
                android:text="One" />
    
            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@android:drawable/list_selector_background"
                android:paddingLeft="4dp"
                android:paddingRight="4dp"
                android:text="Two" />
        </LinearLayout>
    </LinearLayout>
    

    并将您的代码用于 API11+

    【讨论】:

    • 当我想在同一个应用程序中支持 10+ 时会发生什么?另外,当您使用 appcompat 时,您不会获得样式吗?为什么我需要实现这个?
    • 它适用于同一个应用程序,使用资源限定符。在这里阅读更多:developer.android.com/guide/topics/resources/…
    猜你喜欢
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    相关资源
    最近更新 更多