当colorprimary为白色时,警报对话框文本不可见

时间:2017-07-14 11:04:01

标签: android android-alertdialog android-theme textcolor

在我的应用主题中,colorPrimary是白色的。因此,在Android N下面看不到alertdialog的textcolor。然后,我为alertdialog创建了一个自定义主题,但仍无效。

    <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@android:color/transparent</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:windowLightStatusBar">true</item>
    <item name="android:windowAnimationStyle">@style/CustomActivityAnimation</item>
</style>

这是我的自定义警告对话框主题。我的对话框有arrayadapter。

<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColor">#000000</item>
    <item name="android:textColorPrimary">#000000</item>
</style>

我在代码后使用了这个主题。

private void showAccountSettingsPopUp(){
    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        builder = new AlertDialog.Builder(this);
    } else {
        builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
    }
    List<String> stringList = new ArrayList<>();
    stringList.add(getString(R.string.blocked_list));
    stringList.add(getString(R.string.edit_my_profile));
    stringList.add(getString(R.string.delece_acc));
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, stringList);
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            switch (i){
                case 0:
                    startActivity(new Intent(SettingsActivity.this, BlockedUserActivity.class));
                    break;
                case 1:
                    startActivity(new Intent(SettingsActivity.this, EditProfilActivity.class));
                    break;
                case 2:
                    showTwoButtonAlert(getString(R.string.are_you_sure), getString(R.string.delete_acc_text), false);
                    break;
            }
        }
    });
    builder.show();
}

3 个答案:

答案 0 :(得分:0)

您可以尝试将您为警报对话框定义的主题设置为app:popupTheme 例如在xml中

<LinearLayout
...
        app:popupTheme="@style/AlertDialogTheme"
        app:theme="@style/AppTheme"
...
/>

答案 1 :(得分:0)

使用

之类的风格
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">#FFCC00</item>
    <item name="android:textColorPrimary">@color/theme_color_blue</item>
    <item name="android:background">#FFF</item>
</style>

答案 2 :(得分:0)

问题不是主题。这与arrayadapter列表项有关。我创建了textview,其颜色为黑色,并将其设置为arrayadapter listitem,如下所示。

我用这个,

ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(), R.layout.textview_arrayadapter, stringList);

而不是

ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, stringList);