2012-09-04 24 views
3

我有一個自定義alertdialog是這個膨脹的自定義佈局:的Android定製alertdialog上ICS不同,薑餅

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/infoLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:theme="@style/AppTheme" > 


    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:weightSum="2" > 

     <TextView 
      android:id="@+id/infoVersionTitle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="right|center" 
      android:text="@string/infoVersion" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <TextView 
      android:id="@+id/infoVersionTitleValue" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/infoDetailText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/linearLayout1" 
     android:padding="10dp" /> 

</RelativeLayout> 

我在清單文件中有這樣的:

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="15" /> 
........ 
<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 

而且我有風格.XML這樣定義的:這樣定義

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
    <style name="AppTheme" parent="android:Theme.Light"></style> 
</resources> 

style.xml V11:

這樣定義
<resources> 
    <style name="AppTheme" parent="android:Theme.Light"></style> 
</resources> 

而且style.xml V14:

<resources> 
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" /> 
</resources> 

當4.0.3設備上運行此它顯示這樣的:

enter image description here

而且在2.3運行.3設備顯示如下:

enter image description here

2.3.3設備,文本幾乎是不可讀的,我想顯示白色背景(標題欄包含)

是否有可能使定製alertdialog秀上的所有設備,如它顯示了4.0.3?我看過this,但似乎無法弄清楚。

任何解決方案?

回答

1

您可以使用ActionBarSherlock用於此目的

檢查描述Theming頁對話框

+0

謝謝,但在尋找的東西,而無需使用第三方解決方案。將調查看看。但是在2.3.3設備上,我可以做些什麼,自定義alertdialog顯示黑色,但白色字母。這種方式的文本將是可讀的 – Favolas

+1

如果你不想使用任何第三方解決方案,那麼你可以看看他們的源代碼,並瞭解他們是如何做到的。 這裏是[Holo every where]的示例和源代碼(https://github.com/ChristopheVersieux/HoloEverywhere) – Amir

+0

好吧,我們將研究這一點。在薑餅設備上,沒有辦法強制使用默認薑餅主題的alertdialog顯示嗎? – Favolas

8

嘗試調用AlertDialog.Builder#setInverseBackgroundForced(true)當您創建您的對話框。

0

爲了確保兼容性所有設備:

setInverseBackgroundForced(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? false 
            : true) 

這使得下面HoneyCromb正常顯示確保設備及以下設備倒!

下面是一個例子:

final AlertDialog.Builder dialog = new AlertDialog.Builder(this) 
dialog.setInverseBackgroundForced(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? false 
         : true); 
dialog.setMessage("Test Dialog!"); 
dialog.create().show(); 

請參閱該文檔:

http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setInverseBackgroundForced(boolean)