您能否使警报对话框占据屏幕宽度的100%?

时间:2019-03-31 10:29:40

标签: android alertdialog android-custom-view android-dialogfragment android-dialog

我正在尝试使我的警报对话框(不是自定义对话框)从头到尾占据屏幕上宽度的100%,但是即使我将其设置为与父级宽度匹配,它仍会占据屏幕宽度的90%宽度,左右之间有一些间隙(也试图将重力设置为底部,但底部也有一些空间)。不知道我是否需要自定义对话框来执行此操作,还是可以通过某种方式将警报对话框占用整个屏幕宽度而无需自定义?有任何想法吗? 这是我的代码供参考:

 <body data-spy="scroll" data-target=".navbar .fixed-top" data-offset="50">
        <div class="container-fill main_container clearfix">
            <div class="row no-gutters">
                <div class="col-sm-2 side_bar_n">  <!-- Nav bar here -->
                    <ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion fixed-top" id="accordionSidebar">
                        ........ 
                    </ul>
                </div>
                <div class="col-sm-7">  <!-- Card grid -->
                    <div class="container grid_container clearfix">
                      <h1>Recherche de carte</h1>
                      <div class="row no-gutters">
                          <div class="col-sm-2"><img src="cards/287044.jpg" class="rounded grid_space img-fluid" alt="Cinque Terre"></div>
                            ........
                          <div class="col-sm-2"><img src="cards/287044.jpg" class="rounded grid_space img-fluid" alt="Cinque Terre"></div>

                      </div>
                    </div>
                </div>
                <div class="col-sm-2 float-right"> <!-- Card display -->
                    <div class="container-fluid fixed-top clearfix">
                        <div class="card card_body">
                          <img class="card-img-top rounded" src="cards/368262.jpg" alt="Card image">
                              <div class="card-body">
                                <h4 class="card-title">Rythme of the Wild</h4>
                                <p class="card-text">Creature spells you control can't be countered.NonToken creatures you control have riot (+1/+1 or haste when entering the battlefield.)</p>
                                <a href="#" class="btn btn-primary">See Profile</a>
                              </div>
                        </div>
                    </div>
                </div> 
            </div>
        </div>
    </body>

1 个答案:

答案 0 :(得分:1)

尝试以下代码

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);

或在您的style.xml中添加自定义主题

 <style name="DialogTheme" parent="android:Theme.Dialog">

<item name="android:layout_width">match_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>

在扩大对话的同时设置此主题

dialog = new Dialog(this, R.style.DialogTheme);