2013-02-24 62 views
0

我解決了堆棧溢出的許多問題。我遇到了特殊的問題,所以現在是時候直接問你第一次了。在GB和ICS上顯示差異的按鈕 - 在帶有ABS的ICS上看不到的按鈕

我使用ActionBarSherlock。我希望我的應用在任何設備上看起來都一樣。我需要對話框,所以我決定使用ABS的對話框主題。所以我爲我的自定義對話框創建了一個活動,並且我將它設計成即使在早期的Android版本上也像Holo。

這就是它是如何看在Android 2.3.3模擬器:

https://dl.dropbox.com/u/49293039/problem2.jpg(對不起,我不能發佈它作爲一個圖像由於缺少我的名譽......的)

我喜歡這一點。但是,當我想測試它ICS和JB設備/仿真器,我看到...

https://dl.dropbox.com/u/49293039/problem1.jpg

正如你看到的,我的按鈕沒有顯示。讓我爲您提供一個快速查看我的源代碼:

@佈局/ my_dialog.xml的按鈕欄實現部分:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:layout_margin="0dp" 
    android:orientation="vertical" 
    android:padding="0dp"> 

    <View 
    style="@style/HorizontalDivider" 
    /> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="0dp" 
    android:orientation="horizontal" 
    android:padding="0dp"> 

     <Button 
     android:id="@+id/cancelButton" 
     android:text="@string/cancel_button" 
     style="@style/HoloBarButton" 
     /> 

     <View 
     style="@style/VerticalDivider" 
     /> 

     <Button 
     android:id="@+id/proceedButton" 
     android:text="@string/add_button" 
     style="@style/HoloBarButton"/> 

    </LinearLayout> 
</LinearLayout> 

@價值觀/ styles.xml

<style name="HorizontalDivider"> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">1dp</item> 
    <item name="android:background">?android:attr/listDivider</item> 
    <item name="android:layout_margin">0dp</item> 
</style> 

<style name="VerticalDivider"> 
    <item name="android:layout_width">1dp</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:background">?android:attr/listDivider</item> 
    <item name="android:layout_margin">0dp</item> 
</style> 

<style name="HoloBarButton"> 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:layout_height">match_parent</item> 
    <item name="android:background">@android:color/transparent</item> 
    <item name="android:layout_margin">0dp</item> 
    <item name="android:textColor">#ffffff</item> 
    <item name="android:layout_weight">50</item> 
</style> 

任何想法如何解決這個問題?實現兩個版本的對話框(本地版本爲4.0以上,而舊版本爲Android版本)將帶來更多的努力。是否有可能解決這個問題,或者是否有我的錯?

我試圖通過將targetSdkVersion從15更改爲8和10(最小爲8)來解決它,但它沒有幫助。 如果不清楚,請詢問。謝謝你的努力。

回答

0

我解決它。問題出在部分代碼中,我沒有在那裏發佈。它是@ layout/my_dialog.xml中的代碼。 LinearLayout中的一個在layout:height中有match_parent,所以LinearLayout和我的按鈕沒有空間。令人驚訝的是,舊的API沒有問題。因此,請務必確定佈局參數,並且不要相信在一個平臺上顯示正確,嘗試在每個平臺上運行您的應用程序,如果出現問題,請在您的代碼中查找錯誤。

0

問題是在你的按鈕樣式,改變你的HoloBarButton這個

<style name="HoloBarButton"> 
    <item name="android:layout_width">0dp</item> 
    <item name="android:layout_height">match_parent</item> 
    <item name="android:background">@android:color/transparent</item> 
    <item name="android:layout_margin">0dp</item> 
    <item name="android:textColor">#ffffff</item> 
    <item name="android:layout_weight">1</item> 
</style> 
+0

不幸的是,這不是。按鈕仍然不顯示。感謝您的迴應。 – 2013-02-24 15:41:05