2014-10-09 17 views
5

Mam problem z niestandardowego widoku w oknie na Android API 10.Android AlertDialog produkuje czarny tekst z czarnym tłem

używam AlertDialog.Builder skonstruować moje okno. Dołączam niestandardowy panel widoku, używając polecenia setView w programie budującym.

Działa to na większości interfejsów API, z którymi testowałem. Styl zmienia się nieco w zależności od urządzenia, ale tego właśnie chcę, aby styl pasował do domyślnego urządzenia.

Mój problem polega na tym, że w interfejsie API 10 dowolny tekst w moim widoku niestandardowym jest czarny na czarnym tle.

Każdy tekst wstawiony za pomocą AlertDialog.Builder.setMessage() pojawia się poprawnie.

Jakim magicznym atrybutem/stylem jest budowniczy dialogów służący do określania wyglądu tekstu?

Motywem mojej aplikacji jest Theme.AppCompat.Light.

Oto moja onCreateDialog metoda:

public Dialog onCreateDialog(Bundle savedInstanceState) { 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 
    final View view = inflater.inflate(R.layout.fragment_status_dialog, null); 
    mStatusTextView = (TextView) view.findViewById(R.id.text_status); 
    mConnectedDeviceTextView = (TextView) view.findViewById(R.id.text_connected_device); 

    MainService.ServiceState state = null; 
    if (getArguments().containsKey(SERVICE_STATUS_ARG_KEY)) { 
     state = (MainService.ServiceState) getArguments().getSerializable(SERVICE_STATUS_ARG_KEY); 
    } 
    setState(state); 

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    builder.setView(view); 
    builder.setMessage("This will show up just fine."); 
    builder.setTitle(getString(R.string.status_title)); 
    builder.setNegativeButton(R.string.dialog_back_button_text, null); 
    builder.setNeutralButton(R.string.dialog_connect_to_text, new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      mListener.onDialogConnectTo(); 
     } 
    }); 
    // Create the AlertDialog object and return it 
    return builder.create(); 
} 

Oto mój fragment_status_dialog układ

<?xml version="1.0" encoding="utf-8"?> 

    <RelativeLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:padding="18dp"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="@string/status_starting" 
    android:id="@+id/text_status"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="@string/status_connected_to_unknown" 
    android:paddingStart="4dp" 
    android:paddingLeft="4dp" 
    android:paddingRight="4dp" 
    android:id="@+id/text_connected_device" 
    android:layout_toRightOf="@+id/text_status" 
    android:layout_toEndOf="@+id/text_status"/> 
    </RelativeLayout> 

Uwaga, próbowałem https://stackoverflow.com/a/24505312/2350083 ale nie naprawić.

ex

+1

Spróbuj wywołać 'AlertDialog # setInverseBackgroundForced (true)'. –

+0

Alex, to rozwiązanie wydaje się działać dla mnie! Dziękuję Ci! Przetestowałem to do tej pory na urządzeniach korzystających z interfejsu API 10,13,15,19 – Jon

+0

Miło to słyszeć! Dodałem to jako odpowiedź. –

Odpowiedz

2

Spróbuj zadzwonić pod numer AlertDialog#setInverseBackgroundForced(true).

0

co wystarczy ustawienie koloru tekstu? Np .:

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="@android:color/white" 
    android:text="@string/status_starting" 
    android:id="@+id/text_status"/> 

Aplikacja TextView używa domyślnego koloru tekstu urządzenia (lub aplikacji). Jeśli ustawisz kolor specjalnie dla TextView, zostanie on przesłonięty na urządzeniach niezależnie od API.

+1

Różne interfejsy API mają różne style. Na przykład mój Dell Streak 7 pokazuje wszystkie okna dialogowe na białym tle. – Jon

Powiązane problemy