【问题标题】:How to remove transparent dark background outside of dialog box如何删除对话框外的透明深色背景
【发布时间】:2014-02-23 23:52:56
【问题描述】:

我想去除对话框外的透明深色背景。

我试过了:

final Dialog dialog = new Dialog(this);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE));
        this.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE));
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.spinner_layout);
         getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);

【问题讨论】:

    标签: android android-dialog


    【解决方案1】:

    除了chuky的回答;

    如果你的 minSdkVersion 值大于等于 14,你可以使用 setDimAmount() 方法。

    dialog.getWindow().setDimAmount(float amount);
    

    根据reference;

    amount 新的暗淡量,从 0 表示没有暗淡到 1 表示完全暗淡。

    As stated previously,你可以清除窗口标志。

    【讨论】:

      【解决方案2】:

      您的问题已经回答here

      链接中的代码:

      将此添加到您的styles.xml:

      <?xml version="1.0" encoding="utf-8"?>
      <resources>
        <style name="Theme.DoNotDim" parent="android:Theme">
          <item name="android:backgroundDimEnabled">false</item>
        </style>
      </resources>
      

      然后将主题应用于您的活动:

      <activity android:name=".SampleActivity" android:theme="@style/Theme.DoNotDim">
      

      【讨论】:

      • 感谢您的解决方案,节省了我很多时间!
      【解决方案3】:

      希望对你有所帮助...

      dialog.getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);
      dialog.getWindow().setDimAmount(0.0f);
      dialog.show();
      

      【讨论】:

        【解决方案4】:

        这对我不起作用

        <item name="android:backgroundDimEnabled">false</item>
        

        我使用背景暗淡量而不是启用背景暗淡

        <?xml version="1.0" encoding="utf-8"?>
        <resources>
          <style name="Theme.DoNotDim" parent="android:Theme">
            <item name="android:backgroundDimAmount">0</item>
          </style>
        </resources>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-04-30
          • 2022-01-23
          • 1970-01-01
          • 1970-01-01
          • 2023-03-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多