2012-12-22 28 views
0

我一直在使用下面的代碼在XML佈局文件:代碼現在給錯誤問心無愧新ADT

<!-- Copyright (C) 2008 The Android Open Source Project 

    Licensed under the Apache License, Version 2.0 (the "License"); 
    you may not use this file except in compliance with the License. 
    You may obtain a copy of the License at 

      http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, software 
    distributed under the License is distributed on an "AS IS" BASIS, 
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    See the License for the specific language governing permissions and 
    limitations under the License. 
--> 

<!-- OK confirm and cancel buttons. --> 
<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:divider="?android:attr/dividerHorizontal" 
     android:showDividers="beginning" 
     android:paddingTop="16dip"> 

    <LinearLayout 
      style="?android:attr/buttonBarStyle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:measureWithLargestChild="true"> 

     <LinearLayout android:id="@+id/leftSpacer" 
       android:layout_weight="0.25" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:visibility="gone" /> 

     <Button android:id="@+id/cancel_button" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left" 
       android:layout_weight="1" 
       android:text="@string/cancel" 
       android:maxLines="2" 
       style="?android:attr/buttonBarButtonStyle" /> 

     <Button android:id="@+id/ok_button" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" 
       android:layout_weight="1" 
       android:text="@string/install" 
       android:maxLines="2" 
       android:filterTouchesWhenObscured="true" 
       style="?android:attr/buttonBarButtonStyle" /> 

     <LinearLayout android:id="@+id/rightSpacer" 
       android:layout_width="0dip" 
       android:layout_weight="0.25" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:visibility="gone" /> 

    </LinearLayout> 
</LinearLayout> 

這創造了一個淡淡的線分開無邊距按鍵爲安裝在ICS或以上的應用程序時所看到或在手機應用程序。它曾經在Froyo和Gingerbread中運行良好,但是,由於更新到最新版本的ADT,這個XML佈局文件給出了編譯錯誤,說明了按鈕欄樣式,並且只能用於API Level 11和更高版本。

如前所述,它用於編譯罰款,有什麼我可以做的,以解決它。一旦發生編譯錯誤,就是增加清單中的API級別,保存並再次降低它。現在ADT不會再抱怨,直到我再次打開XML文件。

回答

2

但是,因爲更新到ADT的最新版本,所以這個XML佈局文件給出編譯錯誤,說按鈕欄樣式,只能用於API Level 11及以上版本。

這是因爲thoseattributes在API級別11

開始只定義有什麼我可以做它用在API級別進行修復

停止10及以下,因爲它可能會給你一些你還沒有看到的問題。例如,您可以將此佈局移至res/layout-v11/,並在res/layout/中創建不具有這些style屬性的相同佈局文件的另一版本。

+0

是的我知道屬性只在API 11中定義,我想知道他們爲什麼能夠編譯和使用舊的ADT插件。 我不能從API複製buttonBar屬性嗎? – user1424720

+0

@ user1424720:「我想知道他們爲什麼能夠編譯和使用舊的ADT插件」 - 我無法回答。 「我不能從API複製buttonBar屬性嗎?」 - 只有當您可以回到過去並更新1億多部手機。 – CommonsWare

+0

好的,謝謝你的時間,我會製作兩個單獨的xml文件 – user1424720