【问题标题】:Alert dialog text not visible when colorprimary is white当 colorprimary 为白色时,警报对话框文本不可见
【发布时间】:2017-07-14 11:04:00
【问题描述】:

在我的应用主题中 colorPrimary 是白色的。所以,alertdialog 的 textcolor 在 Android N 下是不可见的。然后,我为 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();
}

【问题讨论】:

    标签: android android-alertdialog android-theme textcolor


    【解决方案1】:

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

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

    【讨论】:

    • 这不起作用。结果还是一样。我找到了解决方案。
    【解决方案2】:

    使用类似的样式

    <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>
    

    【讨论】:

      【解决方案3】:

      问题不是主题。这与 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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-24
        • 1970-01-01
        • 2016-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多